Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Enumerating data formats currently available on the clipboard
Custom GDI+ class
Mapping and disconnecting network drives
Winsock: sending email messages (SMTP, port 25)
Capturing keyboard activity of another application with the Raw Input API (VFP9)
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Converting Unicode data from the Clipboard to a character string using a given code page
Enumerating raw input devices attached to the system (keyboard, mouse, human interface device)
Disk in drive A:
How to display the Properties dialog box for a file (ShellExecuteEx)
Enumerating network resources
Detecting changes in connections to removable drives (VFP9)
Splash Screen for the VFP application
How to download a file from the FTP server using FtpGetFile
Using Font and Text functions
Using EnumPrinters function to enumerate locally installed printers
How to play AVI file on the _screen
Retrieving the name of the network resource associated with a local device
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Running MSDOS Shell as a child process with redirected input and output (smarter RUN command)
Creating irregularly shaped FoxPro form using transparency color key
Creating a console window for Visual FoxPro application
How to put a horizontal text scrolling on the form (a news line)
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: 71  
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 (23.22.212.158)
7 sec.Example: 'Retrieving a universal form for the drive-based path for a network resource'
1.65 hrs.Function: 'NetFileGetInfo'
 Example: 'How to retrieve list of system DSNs (Data Source Name) with parameters'
4.07 hrs.Function: 'GetPrivateProfileString'
Function group: 'Registry'
 Example: 'Placing On-screen Alert on top of all windows'
 Function: 'CreateMailslot'
5.34 hrs.Example: 'How to delete all print jobs for a printer'
 
Function group: 'Path'
6.37 hrs.Function: 'CryptUnprotectData'
Function group: 'Cryptography Reference'
8.81 hrs.Example: 'How to generate GUID values'
Google
Advertise here!