Using Win32 functions in Visual FoxPro Image Gallery
Keyboard Input
..msdn
ActivateKeyboardLayout
BlockInput
EnableWindow
GetActiveWindow
GetAsyncKeyState
GetFocus
GetKBCodePage
GetKeyboardLayout
GetKeyboardLayoutList
GetKeyboardLayoutName
GetKeyboardState
GetKeyNameText
GetKeyState
IsWindowEnabled
keybd_event
MapVirtualKey
RegisterHotKey
SetFocus
SetKeyboardState
ToAscii
UnregisterHotKey
VkKeyScan
Code examples:
An alternative way of setting Form.Closable to False
Animating a transition of the VFP form (a wire-frame rectangle)
Attaching menu to a top-level form
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
Creating a clipping region from the path selected into the device context of a form
Disabling drawing in the VFP form
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
Dragging files from Explorer window and dropping them on FoxPro control (requires VFP9)
Drawing a window caption using the DrawCaption routine
Drawing standard Windows icons
Form Magnifier
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file
GDI+: saving image of FoxPro form to graphics file (BMP, GIF, JPG, PNG, TIF)
GDI+: sending image of FoxPro form to printer
GetFocus returns a HWND value
How to block the ALT+TAB shortcut (WinXP)
How to block the PrintScreen key
How to copy the image of a form to the Clipboard using Bitmap API functions
How to create transparent areas inside a form -- punching holes in the form
How to drag a Form not using its Titlebar or Caption
How to intercept window messages sent to VFP form
How to print FoxPro form
How to print FoxPro form -- II
How to put a horizontal text scrolling on the form (a news line, marquee)
How to put a vertical text scrolling on the form (a movie cast)
How to start the screen saver and how to find whether the screen saver is active
How to view icons stored in executable files (Icon Viewer)
Placing a button on the VFP form as a new child window
Retrieving top-child window for the VFP form
Retrieving window and menu help context identifiers
Round FoxPro form
Running a regular FoxPro form while main VFP window is minimized
Setting the mouse capture to the specified window
Setting the Window Region for a form
Shortcut Menu Class
Storing screen shot of a form to bitmap file
Storing screen shot of a form to enhanced metafile (*.emf)
The window and its ancestors
Tracking mouse movement to detect when to start dragging
Using Common Controls: the Header Control
Using FrameRgn for displaying system colors
Using IsChild() for testing ThisForm.ShowWindow property
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: 42  
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-2014 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.68), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.167.185.110)
8 sec.Function: 'CryptGetHashParam'
Function group: 'Cryptography Reference'
3 day(s)Function: 'RtlDecompressBuffer'
 Example: 'Placing a button on the VFP form as a new child window'
 
Function group: 'Network Management'
 Function: 'NetShareDel'
Function group: 'Network Management'
 Example: 'Retrieving information specific to the current Time Zone'
 Example: 'How to retrieve adapter information for the local computer (including MAC address)'
Google
Advertise here!