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
GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image file

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:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

Related code samples:
  • GDI+: Storing content of the Clipboard to a bitmap file
  • Copying picture of the active form to the Clipboard using Bitmap API functions
  • Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
  • Storing content of the Clipboard to a bitmap file
  • Storing screen shot of a form to a bitmap file

  •  
    SET PROCEDURE TO gdiplus ADDITIVE
    DO decl
     
    * an instance of gdiplusinit should be created before
    * and released after using any of gdi+ objects
    PRIVATE gdiplus
    gdiplus = CREATEOBJECT("gdiplusinit")
     
    = FormToClip(GetFocus())
    *= FileToClip("c:\windows\forest.bmp")
    * end of main
     
    PROCEDURE FormToClip(hwindow)
    #DEFINE SRCCOPY  0x00CC0020
        LOCAL hdc, bmp, nWidth, nHeight
        hdc = GetWindowDC(hwindow)
        STORE 0 TO nWidth, nHeight
        = GetWinRect(hwindow, @nWidth, @nHeight)
     
        bmp = CREATEOBJECT("gdibitmap", m.nWidth, m.nHeight)
        WITH bmp
            .graphics.GetDC
            = BitBlt(.graphics.hdc, 0,0, .imgwidth, .imgheight,;
                m.hdc, 0,0, SRCCOPY)
            .graphics.ReleaseDC
        ENDWITH
        = ReleaseDC(m.hwindow, m.hdc)
     
        IF NOT img2clip(bmp)
            ? "Error code:", bmp.errorcode
        ENDIF
     
    PROCEDURE FileToClip(cFilename)
        LOCAL img, nResult
        img = CREATEOBJECT("gdiimage", cFilename)
     
        IF NOT img2clip(img)
            ? "Error code:", img.errorcode
        ENDIF
     
    FUNCTION img2clip(img)
    * sends gdi+ image or bitmap object to the Clipboard
    #DEFINE CF_BITMAP  2
        IF img.GetHBITMAP() <> 0
            = OpenClipboard(0)
            = EmptyClipboard()
            = SetClipboardData(CF_BITMAP, img.hbitmap)
            = CloseClipboard()
            = LockClipboardData()
        ENDIF
    RETURN (img.errorcode=0)
     
    PROCEDURE LockClipboardData
    * the shortest way of locking clipboard data I have found;
    * otherwise it does not survive beyond the lifetime of its parent gdi+ object
        = OpenClipboard(0)
        LOCAL nIndex, hData
        nIndex = 0
        DO WHILE .T.
            nIndex = EnumClipboardFormats(nIndex)
            IF nIndex = 0
                EXIT
            ELSE
                hData = GetClipboardData(nIndex)
            ENDIF
        ENDDO
        = CloseClipboard()
     
    PROCEDURE GetWinRect(hwindow, nWidth, nHeight)
    #DEFINE maxDword  0xffffffff
        LOCAL lpRect, nLeft, nTop, nRight, nBottom
        lpRect = REPLI (Chr(0), 16)
        = GetWindowRect (hwindow, @lpRect)
        nRight  = buf2dword(SUBSTR(lpRect, 9,4))
        nBottom = buf2dword(SUBSTR(lpRect, 13,4))
     
        nLeft = buf2dword(SUBSTR(lpRect, 1,4))
        IF nLeft > nRight
            nLeft = nLeft - maxDword
        ENDIF
        nTop = buf2dword(SUBSTR(lpRect, 5,4))
        IF nTop > nBottom
            nTop = nTop - maxDword
        ENDIF
        nWidth = nRight - nLeft
        nHeight = nBottom - nTop
    RETURN
     
    PROCEDURE decl
        DECLARE INTEGER CloseClipboard IN user32 
        DECLARE INTEGER EmptyClipboard  IN user32 
        DECLARE INTEGER OpenClipboard IN user32 INTEGER hwnd 
        DECLARE INTEGER GetClipboardData IN user32 INTEGER uFormat
        DECLARE INTEGER EnumClipboardFormats IN user32 INTEGER wFormat
     
        DECLARE INTEGER SetClipboardData IN user32;
            INTEGER wFormat, INTEGER hMem
     
        DECLARE INTEGER GetFocus IN user32
        DECLARE INTEGER GetWindowDC IN user32 INTEGER hwindow
        DECLARE INTEGER ReleaseDC IN user32 INTEGER hwindow, INTEGER hdc
        DECLARE INTEGER GetWindowRect IN user32 INTEGER hwnd, STRING @lpRect 
     
        DECLARE INTEGER BitBlt IN gdi32;
            INTEGER hDestDC, INTEGER x, INTEGER y,;
            INTEGER nWidth, INTEGER nHeight, INTEGER hSrcDC,;
            INTEGER xSrc, INTEGER ySrc, INTEGER dwRop
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    2960 bytes  
    Created: 2004-07-16 11:19:39  
    Modified: 2004-12-05 15:04:21  
    Visits in 7 days: 149  
    Listed functions:
    BitBlt
    CloseClipboard
    EmptyClipboard
    EnumClipboardFormats
    GetClipboardData
    GetFocus
    GetWindowDC
    GetWindowRect
    OpenClipboard
    ReleaseDC
    SetClipboardData
    Printer friendly API declarations
    My comment:
    Call the FormToClip function from a method or event of a FoxPro form when that form is active, i.e. posesses the keyboard focus.

    For the FileToClip make sure the source file name is valid. The source file can be in any of graphics formats supported by the GDI+: BMP, GIF, JPG, TIF, EMF...

    The LockClipboardData function is kind of a lazy way to avoid complexities of locking data on the Clipboard. The SetClipboardData in the code above creates three sets of data on the Clipboard:

  • Bitmap handle (2)
  • BITMAPINFO structure (8)
  • BITMAPV5HEADER structure (17)

    The last two, if not locked properly, are getting wiped out as soon as gdi+ img object is out of scope or released.

    Even if this works on WinXP and Win2K computers, this behaviour of the GetClipboardData looks rather undocumented. As soon as I come with another solution (short enough) I will post it here.

    * * *
    August 2, 2004: Alexander Golovlev in his GDI+ class uses solution that looks better.

    To disconnect image handle from the GDI+ object he applies the CopyImage API function that creates a duplicate of the bitmap handle and then passes this new handle to the SetClipboardData function. That simple :)

    * * *
    An article How To Copy the Screen or Active Window to the Clipboard from Visual Basic published on Microsoft Help and Support page describes a different approach -- the picture of the whole screen is sent to the clipboard by virtually pressing (through the keybd_event call) PrtScr key.

    #kwd: sln_gdiplus.
  • 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.17.90)
    4 sec.Example: 'How to display the port-configuration dialog box for a port on the specified server'
    1.34 hrs.Solution: 'LanguageBar ActiveX Control'
    3.08 hrs.Examples
    Page 10
     
    3.32 hrs.Example: 'Printing Image File, programmatically set print page orientation to landscape'
     Function: 'ConvertSidToStringSid'
    Function group: 'Security'
    5.19 hrs.Function: 'LocalSize'
    Function group: 'Memory Management'
     Function: 'LookupAccountName'
    5.89 hrs.Example: 'How to display advanced Task Dialog (Vista)'
     Example: 'How to set Creation Date/Time for a folder (WinNT)'
    Google
    Advertise here!