Using Win32 functions in Visual FoxPro Image Gallery
Window
..msdn
CloseWindow
CreateWindow
CreateWindowEx
DestroyWindow
EndTask
FindWindow
FindWindowEx
GetAncestor
GetClientRect
GetDesktopWindow
GetForegroundWindow
GetGUIThreadInfo
GetParent
GetShellWindow
GetWindow
GetWindowInfo
GetWindowPlacement
GetWindowRect
GetWindowText
GetWindowTextLength
GetWindowThreadProcessId
InternalGetWindowText
IsChild
IsIconic
IsWindow
IsWindowVisible
IsZoomed
MoveWindow
RealGetWindowClass
SetForegroundWindow
SetLayeredWindowAttributes
SetParent
SetWindowPos
SetWindowText
ShowWindow
SwitchToThisWindow
Code examples:
Creating a window using CreateWindowEx function
Displaying dimmed window behind VFP top-level form
Displaying hypertext links with the SysLink control (VFP9, Comctl32.dll)
How to make a VFP form fading out when released (GDI version)
How to make a VFP form fading out when released (GDI+ version)
Placing a button on the VFP form as a new child window
Placing On-screen Alert on top of all windows
Splash Screen for the VFP application
Using Common Controls: the Header Control
Using Month Calendar Control (VFP9, Comctl32.dll)
Placing a button on the VFP form as a new child window

User rating: 10/10 (3 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:
This code demonstrates how to create a child window (the regular Windows button is always a child window for its container).

It is known that native FoxPro controls are not windows, as they are in VB or Delphi sets of controls, just name a few. Most of the times it creates a small inconvenience, unless you need more control on their properties.



For example, I do not know how to shape the native VFP CommandButton control to anything but a rectangle. Correct me if I am wrong. Transparent image does not solve the problem.
 
DO declare
 
LOCAL oForm As Tform
oForm=CREATEOBJECT("Tform")
oForm.Show()
READ EVENTS
* end of main
 
DEFINE CLASS Tform As Form
#DEFINE WM_PARENTNOTIFY 0x0210
#DEFINE WM_COMMAND 0x0111
#DEFINE WM_LBUTTONDOWN 0x201
#DEFINE WM_RBUTTONDOWN 0x204
#DEFINE GWL_WNDPROC -4
PROTECTED hWindow, hOrigProc
    hWindow=0
    hOrigProc=0
    Caption = "Adding the Windows Button to the form"
    Height = 250
    Width = 450
    Autocenter = .T.
    hButton = 0
 
    ADD OBJECT chAddButton As CheckBox WITH;
    Left=20, Top=20, Autosize=.T., Caption="Add Button"
 
PROCEDURE Destroy
    THIS.RemoveButton
    CLEAR EVENTS
 
PROCEDURE Activate
    IF THIS.hWindow = 0
        THIS.hWindow = GetFocus()
        THIS.hOrigProc = GetWindowLong(THIS.hWindow, GWL_WNDPROC)
 
        * link WM_PARENTNOTIFY window message to a method
        IF VERSION(5) >= 900
            = BINDEVENT(THIS.hWindow, WM_PARENTNOTIFY, THIS, "WindowProc")
            = BINDEVENT(THIS.hWindow, WM_COMMAND, THIS, "WindowProc")
        ENDIF
    ENDIF
 
PROCEDURE RemoveButton
    IF DestroyWindow(THIS.hButton) <> 0
        THIS.hButton = 0
    ENDIF
 
PROCEDURE AddButton
#DEFINE GWL_HINSTANCE -6
#DEFINE BS_DEFPUSHBUTTON 1
#DEFINE BS_PUSHBUTTON 0
#DEFINE BS_OWNERDRAW 0x000b
#DEFINE WS_VISIBLE 0x10000000
#DEFINE WS_CHILD 0x40000000
 
    LOCAL hApp, hParentHWnd, lnStyle, lnStyleX,;
        lnX, lnY, lnWidth, lnHeight
 
*    lnStyle = WS_VISIBLE+WS_CHILD+BS_PUSHBUTTON)
    lnStyle = BITOR(WS_VISIBLE, WS_CHILD, BS_PUSHBUTTON)
    lnStyleX = 0
 
    * handle to the window hosting the button
*    hParentHWnd=GetFocus()
    hParentHWnd=ThisForm.HWnd  && will not work for ShowWindow=2
 
    * handle to application instance
    hApp = GetWindowLong(hParentHWnd, GWL_HINSTANCE)
 
    * unique child-window identifier
    lnId = VAL(SYS(3))
 
    * size and position
    lnX = 140
    lnY = 50
    lnWidth = 100 
    lnHeight = 28
 
    * the predefined control class BUTTON is used 
    THIS.hButton = CreateWindow (lnStyleX, "BUTTON",;
        "True &Button", lnStyle,;
        lnX, lnY, lnWidth, lnHeight,;
        hParentHWnd, lnId, hApp, 0)
 
PROTECTED PROCEDURE WindowProc(hWindow as Integer,;
    nMsgID as Integer, wParam as Integer, lParam as Integer)
* requires VFP9, otherwise ignored
 
    LOCAL nReturn
    nReturn=0
 
    DO CASE
    CASE nMsgID=WM_COMMAND
        ACTIVATE SCREEN
        ? "WM_COMMAND: wParam=" + LTRIM(STR(wParam)) +;
            ", lParam=" + LTRIM(STR(lParam))
 
    CASE nMsgID=WM_PARENTNOTIFY
        ACTIVATE SCREEN
        ? "WM_PARENTNOTIFY: wParam=" + LTRIM(STR(wParam)) +;
            ", lParam=" + LTRIM(STR(lParam))
 
        DO CASE
        CASE wParam=WM_LBUTTONDOWN
            ?? " -- Left Button pressed"
        CASE wParam=WM_RBUTTONDOWN
            ?? " -- Right Button pressed"
        ENDCASE
 
    OTHERWISE
    * pass control to the original window procedure
        nReturn = CallWindowProc(THIS.hOrigProc, THIS.hWindow,;
            m.nMsgID, m.wParam, m.lParam)
    ENDCASE
RETURN nReturn
 
PROCEDURE chAddButton.Click
    IF ThisForm.hButton=0
        ThisForm.AddButton
    ELSE
        ThisForm.RemoveButton
    ENDIF
    THIS.Caption = IIF(ThisForm.hButton=0,;
        "Add Button", "Remove Button")
 
ENDDEFINE
 
PROCEDURE declare
    DECLARE INTEGER GetFocus IN user32
 
    DECLARE INTEGER DestroyWindow IN user32;
        INTEGER hWindow
 
    DECLARE INTEGER GetWindowLong IN user32;
        INTEGER hWnd, INTEGER nIndex
 
    DECLARE INTEGER CreateWindowEx IN user32 AS CreateWindow;
        INTEGER dwExStyle, STRING lpClassName,;
        STRING lpWindowName, INTEGER dwStyle,;
        INTEGER x, INTEGER y, INTEGER nWidth, INTEGER nHeight,;
        INTEGER hWndParent, INTEGER hMenu, INTEGER hInstance,;
        INTEGER lpParam
 

User rating: 10/10 (3 votes)
Rate this code sample:
  • ~
3503 bytes  
Created: 2002-02-05 14:42:28  
Modified: 2009-10-29 14:02:51  
Visits in 7 days: 133  
Listed functions:
CreateWindow
CreateWindowEx
DestroyWindow
GetFocus
GetWindowLong
Printer friendly API declarations
My comment:
A click on the button sends a notification (Windows message WM_COMMAND) to the window that owns the button. The VFP form for sure receives this message through its WindowProc function.

With no access to this function there hardly is a way to intercept this message and link a procedure to the click.

There are other predefined control classes like the BUTTON: COMBOBOX, EDIT, LISTBOX, SCROLLBAR, STATIC etc. The BUTTON class allows creating command buttons as well as checkboxes, radiobuttons, buttons with images and icons etc.

* * *
Things changed when VFP9 introduced new BINDEVENT() functionality.

* * *
The WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window.

In VFP9 new BINDEVENT() allows to intercept this message. So tecnically, left and right mouse clicks on such windowed button control can be detected by its parent form and linked to a method.
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:
Denis Carrizo (dcarrizo@starsoft.com.br) | 2005-04-27 12:06:59
Using the new bindevent() feature (VFP 9.0), it is possible get the notification when the button is clicked.

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 (107.22.25.119)
3 sec.Function: 'InitiateShutdown'
Function group: 'System Shutdown'
18.97 min.Example: 'Saving HKEY_LOCAL_MACHINE\\Software\\ODBC Registry Entries to an XML file'
19.03 min.Example: 'GDI+: printing vertical text on VFP reports via generated images (VFP8)'
2.11 hrs.Example: 'How to display a user-defined icon in the MessageBox dialog'
 Example: 'Displaying the color palette stored in an image file'
 Function: 'EnumPrinterData'
3.57 hrs.Function: 'CertFindCertificateInStore'
Function group: 'Cryptography Reference'
 Example: 'How to view icons stored in executable files (Icon Viewer)'
 Function: 'GetObject'
3.86 hrs.Function: 'CreateWindow'
Function group: 'Window'
Google
Advertise here!