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)
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
Using Common Controls: the Header Control

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:
This following code creates a header (ListView style) and places it above a ListBox control. There is no particualr functionality connected to this header. As soon as you find a way to intercept and respond to window messages sent to its window (HHT_ONHEADER, HHT_ONDIVIDER) you can use it.


 
PUBLIC obj
obj = CreateObject("Tform")
obj.Visible = .T.
* end of main
 
#DEFINE WM_PARENTNOTIFY 0x0210
#DEFINE WM_LBUTTONDOWN 0x201
#DEFINE WM_RBUTTONDOWN 0x204
#DEFINE WM_DESTROY 2
#DEFINE GWL_WNDPROC -4
 
DEFINE CLASS Tform As Form
PROTECTED hWindow, hOrigProc, SortOrder
    hWindow=0
    hOrigProc=0
    SortOrder=1
 
    Width=500
    Height=300
    Autocenter=.T.
    Caption=" Using Header control"
 
    ADD OBJECT hdr As Theader WITH;
    hdrLeft=2, hdrTop=2, hdrWidth=495, hdrHeight=21
 
    ADD OBJECT lst As listBox WITH;
    Left=2, Top=25, Width=495, Height=240
 
PROCEDURE Init
    THIS.declare
 
PROTECTED PROCEDURE declare
    DECLARE INTEGER GetFocus IN user32
    DECLARE INTEGER InitCommonControlsEx IN comctl32 STRING @lpInitCtrls
    DECLARE INTEGER GetWindowLong IN user32 INTEGER hWnd, INTEGER nIndex
    DECLARE INTEGER DeleteObject IN gdi32 INTEGER hObject
    DECLARE INTEGER DestroyWindow IN user32 INTEGER hWnd
    DECLARE INTEGER StrDup IN shlwapi STRING @lpsz
    DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
 
    DECLARE INTEGER SetWindowPos IN user32;
        INTEGER hwnd, INTEGER hWndInsertAfter,;
        INTEGER x, INTEGER y, INTEGER cx, INTEGER cy,;
        INTEGER wFlags
 
    DECLARE INTEGER CreateWindowEx IN user32 AS CreateWindow;
        INTEGER dwExStyle, STRING lpClassName, STRING lpWndName,;
        INTEGER dwStyle, INTEGER x, INTEGER y, INTEGER nWidth, INTEGER nHeight,;
        INTEGER hWndParent, INTEGER hMenu, INTEGER hInst, INTEGER lpParam
 
    DECLARE INTEGER CreateFont IN gdi32;
        INTEGER nHeight, INTEGER nWidth, INTEGER nEscapement,;
        INTEGER nOrientation, INTEGER fnWeight, INTEGER fdwItalic,;
        INTEGER fdwUnderline, INTEGER fdwStrikeOut,;
        INTEGER fdwCharSet, INTEGER fdwOutputPrecision,;
        INTEGER fdwClipPrecision, INTEGER fdwQuality,;
        INTEGER fdwPitchAndFamily, STRING lpszFace
 
PROCEDURE Activate
    IF THIS.hdr.hWindow = 0
        THIS.CreateHeader
    ENDIF
 
    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")
        ENDIF
    ENDIF
 
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_PARENTNOTIFY
        ACTIVATE SCREEN
        ? wParam, lParam
 
    OTHERWISE
    * pass control to the original window procedure
        nReturn = CallWindowProc(THIS.hOrigProc, THIS.hWindow,;
            m.nMsgID, m.wParam, m.lParam)
    ENDCASE
RETURN nReturn
 
PROCEDURE CreateHeader
    THIS.hdr.CreateHeader
    THIS.hdr.AddItem ("Id", 50, 0)
    THIS.hdr.AddItem ("First name", 150, 1)
    THIS.hdr.AddItem ("Last name", 150, 2)
    THIS.hdr.AddItem ("Dept.", 150, 3)
    THIS.ShowList
 
PROCEDURE ShowList
    CREATE CURSOR csList (personid N(5),;
        firstname C(20), lastname C(30), dept C(50))
 
    INSERT INTO csList VALUES ( 1, "Alan","Morice","Management")
    INSERT INTO csList VALUES ( 2, "Andrew","Bruce","Management")
    INSERT INTO csList VALUES ( 3, "Crysta","Corera","Management")
    INSERT INTO csList VALUES ( 4, "Annie","Collins","Human Resources")
    INSERT INTO csList VALUES ( 5, "Nancy","Nagel","Human Resources")
    INSERT INTO csList VALUES ( 6, "Roy","Saine","Human Resources")
    INSERT INTO csList VALUES ( 7, "Sandy","Tamburro","Human Resources")
    INSERT INTO csList VALUES ( 8, "Dora","Hu","Business Analysts")
    INSERT INTO csList VALUES ( 9, "Emily","Bell","Business Analysts")
    INSERT INTO csList VALUES (10, "Rino","Henry","Business Analysts")
    INSERT INTO csList VALUES (11, "Tanya","Harding","Business Analysts")
    INSERT INTO csList VALUES (12, "Tracy","Clarke","Business Analysts")
 
    LOCAL cSql
 
    cSql = "SELECT * FROM csList " +;
        "ORDER BY " + LTRIM(STR(THIS.SortOrder)) +;
        " INTO CURSOR csList"
    &cSql
 
    WITH THIS.lst
        .RowsourceType=2
        .RowSource="csList"
        .ColumnCount=4
        .ColumnWidths="47,147,147,147"
        .ListIndex = 1
    ENDWITH
ENDDEFINE
 
DEFINE CLASS Theader As Custom
    hParent=0
    hWindow=0
    hFont=0
    hdrLeft=0
    hdrTop=0
    hdrWidth=0
    hdrHeight=0
    ItemsCount=0
 
PROCEDURE Destroy
    THIS.ReleaseHeader
 
PROCEDURE CreateHeader
#DEFINE WS_CHILD  0x40000000
#DEFINE WS_BORDER 0x00800000
#DEFINE HDS_BUTTONS         2
#DEFINE GWL_HINSTANCE      -6
#DEFINE HWND_BOTTOM         1
#DEFINE SWP_SHOWWINDOW      64
#DEFINE ANSI_CHARSET        0
#DEFINE OUT_OUTLINE_PRECIS  8
#DEFINE CLIP_STROKE_PRECIS  2
#DEFINE PROOF_QUALITY       2
#DEFINE DEFAULT_PITCH       0
#DEFINE WM_SETFONT          48
 
    THIS.ReleaseHeader
 
    THIS.hParent = GetFocus()
 
    * initializing access to Common Controls
    = InitCommonControlsEx (PADR(Chr(8), 4,Chr(0)) + PADR(Chr(255), 4,Chr(0)))
 
    LOCAL lcWindowName, lnStyle, lnStyleX, lnId, hApp
    lnStyle = WS_CHILD + WS_BORDER + HDS_BUTTONS
    lnStyleX = 0
    lnId = Val(SYS(3))
    lcWindowName = "hdr" + SYS(3)
    hApp = GetWindowLong (THIS.hWindow, GWL_HINSTANCE)
 
    THIS.hWindow = CreateWindow(lnStyleX, "SysHeader32",;
        lcWindowName, lnStyle, 0,0,0,0,;
        THIS.hParent, lnId, hApp, 0)
 
    * changing font to Arial, semi-bold, 16 pixels height
    THIS.hFont = CreateFont (16, 0, 0, 0, 600, 0,0,0,;
        ANSI_CHARSET, OUT_OUTLINE_PRECIS, CLIP_STROKE_PRECIS,;
        PROOF_QUALITY, DEFAULT_PITCH, "Arial")
 
    DECLARE INTEGER SendMessage IN user32;
        INTEGER hWnd, INTEGER Msg, INTEGER wParam, INTEGER lParam
    = SendMessage (THIS.hWindow, WM_SETFONT, THIS.hFont, 0)
 
    * positioning
    = SetWindowPos(THIS.hWindow, HWND_BOTTOM,;
        THIS.hdrLeft, THIS.hdrTop,;
        THIS.hdrLeft+THIS.hdrWidth-1, THIS.hdrTop+THIS.hdrHeight-1,;
        SWP_SHOWWINDOW)
 
PROCEDURE ReleaseHeader
    IF THIS.hWindow <> 0
        THIS.RemoveItems
        = DeleteObject(THIS.hFont)
        = DestroyWindow(THIS.hWindow)
        THIS.hWindow = 0
    ENDIF
 
PROCEDURE SendItemMsg (lnMessage, lcItem, lnWidth, lnOrder)
#DEFINE HDI_WIDTH       1
#DEFINE HDI_TEXT        2
#DEFINE HDI_ORDER       128
#DEFINE HDF_LEFT        0
#DEFINE HDM_INSERTITEM  4609
 
    LOCAL lnItemPtr, lcBuffer
    lcItem = STRTRAN(lcItem, Chr(0),"") + Chr(0)
    lnItemPtr = StrDup(@lcItem)
 
    lcBuffer = num2dword(HDI_TEXT+HDI_WIDTH+HDI_ORDER) +;
        num2dword(lnWidth) + num2dword(lnItemPtr) +;
        num2dword(0) + num2dword(Len(lcItem)) +;
        num2dword(0) + num2dword(0) + num2dword(0) +;
        num2dword(lnOrder)
 
    DECLARE INTEGER SendMessage IN user32;
        INTEGER hWnd, INTEGER Msg, INTEGER wParam, STRING @lParam
 
    = SendMessage (THIS.hWindow, lnMessage, 0, @lcBuffer)
    = LocalFree(lnItemPtr)
 
PROCEDURE RemoveItems (lcItem)
#DEFINE HDM_DELETEITEM  4610
    LOCAL lnIndex
    FOR lnIndex=1 TO THIS.ItemsCount
        THIS.SendItemMsg (HDM_DELETEITEM, "", 0, 0)
    ENDFOR
 
PROCEDURE AddItem (lcItem, lnWidth, lnOrder)
#DEFINE HDM_INSERTITEM  4609
    THIS.ItemsCount = THIS.ItemsCount + 1
    THIS.SendItemMsg (HDM_INSERTITEM, lcItem, lnWidth, lnOrder)
ENDDEFINE
 
FUNCTION  num2dword (lnValue)
#DEFINE m0       256
#DEFINE m1     65536
#DEFINE m2  16777216
    LOCAL b0, b1, b2, b3
    b3 = Int(lnValue/m2)
    b2 = Int((lnValue - b3*m2)/m1)
    b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
    b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
7216 bytes  
Created: 2002-04-08 22:15:48  
Modified: 2005-07-26 17:51:27  
Visits in 7 days: 173  
Listed functions:
CreateFont
CreateWindowEx
DeleteObject
DestroyWindow
GetFocus
GetWindowLong
InitCommonControlsEx
LocalFree
SendMessage
SetWindowPos
StrDup
Printer friendly API declarations
My comment:
To display bitmaps use HDI_BITMAP flag. Any item can be adjusted through HDM_GETITEM and HDM_SETITEM messages.

* * *
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 a header 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:
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 (54.234.180.187)
4.54 hrs.Function: 'CryptReleaseContext'
 Function: 'BeginUpdateResource'
11.26 hrs.Example: 'Accessing the list of Windows Recent Documents'
 Function: 'LoadIcon'
 Function: 'GdipCreateMatrix'
13.16 hrs.Example: 'Obtaining I/O counts for the current process'
13.17 hrs.
Function group: 'Synchronization'
14.41 hrs.Example: 'Obtaining the bounding rectangle for the specified device context'
 Example: 'Extensible Storage Engine class library'
 Example: 'Creating the Open dialog box to specify the drive, directory, and name of a file to open'
Google
Advertise here!