Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
FindText -- the hopeless and useless Common Dialog
How to display a Task Dialog (Vista)
Number of clipboard formats available
Retrieving information about the specified icon
Retrieving list of files on the FTP directory
Using Font and Text functions
Using mailslots to send messages on the network
Yet another modal dialog: now HTML-based
Enumerating the subkeys for a given registry key
GDI+: printing image file
GDI+: Scrolling through large image using the mouse
How to retrieve number of objects in the Recycle Bin
Retrieving long values associated with the class of the VFP window
Writing entries to custom Event Log
Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)
CryptoAPI: retrieving list of providers
Displaying printer-properties Property Sheet for the specified printer
Enumerating global and local group accounts on a server (WinNT/XP/2K)
How to hide your program from the Close Program dialog (Win9* only)
How to initiate System shutdown
Reading and setting system access privileges for the current process
Setting properties of the window: caption and user-defined value
GDI+ fun: roach-infested desktop
How to empty the Recycle Bin
How to write and read Window Properties for the specified window

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
A window property is any data assigned to a window. A window property is usually a handle of the window-specific data, but it may be any value. Each window property is identified by a string name.

The EnumProps and EnumPropsEx functions enumerate all window properties for a given window by using an application-defined callback function -- something that VFP is not capable of doing without employing external modules written in other languages.
 
#DEFINE SAMPLE_WIN_PROPERTY "MyWinProperty"
DO declare
 
LOCAL hWindow, hProperty, cBuffer, nBufsize
hWindow = _screen.HWnd
 
IF VARTYPE(oProperty) <> "O"
* this variable must not be released until
* the window property is not required anymore
    PUBLIC oProperty As PChar
 
    oProperty = CREATEOBJECT("PChar",;
        TRANSFORM(DATETIME()))
 
    * creating and assigning window property
    IF SetProp(hWindow, SAMPLE_WIN_PROPERTY,;
        oProperty.GetAddr()) = 0
        ? "SetProp failed with error code:", GetLastError()
        RETURN
    ENDIF
ENDIF
 
* reading window property
hProperty = GetProp(hWindow, SAMPLE_WIN_PROPERTY)
IF hProperty = 0
    ? "GetProp failed with error code:", GetLastError()
    RETURN
ENDIF
 
nBufsize = GlobalSize(hProperty)
cBuffer = REPLICATE(CHR(0), nBufsize)
= MemToStr(@cBuffer, hProperty, nBufsize)
? "Property read:", cBuffer
* end of main
 
PROCEDURE declare
    DECLARE INTEGER GetLastError IN kernel32
    DECLARE INTEGER GlobalSize IN kernel32 INTEGER hMem
 
    DECLARE RtlMoveMemory IN kernel32 As MemToStr;
        STRING @, INTEGER, INTEGER
 
    DECLARE INTEGER SetProp IN user32;
        INTEGER hWindow, STRING lpString,;
        INTEGER hData
 
    DECLARE INTEGER GetProp IN user32;
        INTEGER hWindow, STRING lpString
 
DEFINE CLASS PChar As Session
PROTECTED hMem
 
PROCEDURE Init(lcString)
    THIS.hMem = 0
    THIS.setValue(lcString)
 
PROCEDURE Destroy
    THIS.ReleaseString
 
FUNCTION GetAddr
RETURN THIS.hMem
 
FUNCTION GetValue
    LOCAL lnSize, lcBuffer
    lnSize = THIS.GetAllocSize()
    lcBuffer = SPACE(lnSize)
 
    IF THIS.hMem <> 0
        DECLARE RtlMoveMemory IN kernel32 As MemToStr;
            STRING @, INTEGER, INTEGER
        = MemToStr(@lcBuffer, THIS.hMem, lnSize)
    ENDIF
RETURN lcBuffer
 
FUNCTION GetAllocSize
    DECLARE INTEGER GlobalSize IN kernel32 INTEGER hMem
RETURN Iif(THIS.hMem=0, 0, GlobalSize(THIS.hMem))
 
PROCEDURE SetValue(lcString)
#DEFINE GMEM_FIXED 0 
    THIS.ReleaseString
 
    DECLARE INTEGER GlobalAlloc IN kernel32 INTEGER, INTEGER
    DECLARE RtlMoveMemory IN kernel32 As StrToMem;
        INTEGER, STRING @, INTEGER
 
    LOCAL lnSize
    lcString = lcString + Chr(0)
    lnSize = Len(lcString)
    THIS.hMem = GlobalAlloc(GMEM_FIXED, lnSize)
    IF THIS.hMem <> 0
        = StrToMem(THIS.hMem, @lcString, lnSize)
    ENDIF
 
PROCEDURE ReleaseString
    IF THIS.hMem <> 0
        DECLARE INTEGER GlobalFree IN kernel32 INTEGER
        = GlobalFree (THIS.hMem)
        THIS.hMem = 0
    ENDIF
ENDDEFINE
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2418 bytes  
Created: 2001-12-02 18:58:48  
Modified: 2008-03-28 13:29:58  
Visits in 7 days: 88  
Listed functions:
GetLastError
GetProp
GlobalAlloc
GlobalFree
GlobalSize
SetProp
Printer friendly API declarations
My comment:
The Window Properties can hardly be used for interprocess communication (IPC) due to inability of the GlobalAlloc to create memory blocks shareable between several Win32 processes.

As a tool of assigning data to windows in VFP application this functionality is probably not better than using the AddProperty.

An application can assign properties to windows owned by other processes, but none can read the assigned data except the assigning application itself.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (50.16.36.153)
6 sec.Function: 'InternetGetConnectedState'
Function group: 'Internet Functions (WinInet)'
2.63 hrs.Example: 'Storing the environment strings in cursor'
2.64 hrs.Function: 'NetShareSetInfo'
3.98 hrs.Example: 'How to perform Base64 encoding/decoding using Cryptography API Functions'
Google
Advertise here!