Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Moving shortcut to a specified position on the Windows Desktop
Converting path to original case
How to block the PrintScreen key
How to make application automatically close all documents it opened
Encapsulating access to the Windows Services in a class
How to display a user-defined icon in the MessageBox dialog
Reading and setting Environment variables
Downloading files from the FTP server using InternetReadFile
Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)
Sending email messages with Simple MAPI
How to download this reference`s archive through WinInet functions using InternetOpenUrl
How to find the application associated with a file name
Using the CreateFile
Using the DeleteFile
How to retrieve the number of print jobs queued for the printer
Placing a button on the VFP form as a new child window
Wininet last error description
Connecting a local device to a network resource
DiskFreeSpace class
How to print a bitmap file
Printing Image File, programmatically set print page orientation to landscape
Enumerating print jobs and retrieving information for default printer (JOB_INFO_1 structures)
How to disable the Windows Clipboard (VFP9)
How to draw custom Window Caption on FoxPro form
GDI+: Storing content of the Clipboard to a bitmap 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
Versions:
click to open
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:
  • Storing content of the Clipboard to a bitmap file using GDI API
  • GDI+: copying to the Clipboard (a) image of active FoxPro window/form, (b) image 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 screen shot of a form to a bitmap file

  •  
    SET PROCEDURE TO gdiplus ADDITIVE
    #DEFINE CF_BITMAP 2
    #DEFINE CF_DIB    8
    DO decl
     
    IF IsClipboardFormatAvailable(CF_DIB)=0
        = MESSAGEBOX("No image data found stored " +;
            "on the clipboard.   ")
        RETURN
    ENDIF
     
    * an instance of gdiplusinit should be created before
    * and released after using any of gdi+ objects
    PRIVATE gdiplus As gdiplusinit, img As gdibitmap
    gdiplus = CREATEOBJECT("gdiplusinit")
     
    = OpenClipboard(0)
     
    LOCAL bmp As gdibitmap, hBitmap, hDib, lResult
    hBitmap = GetClipboardData(CF_BITMAP)
    hDib = GetClipboardData(CF_DIB)
    bmp = CREATEOBJECT("gdibitmap")
     
    * use either of two ways to create an instance
    * of the gdibitmap object
    *lResult = bmp.CreateFromHBITMAP(hBitmap)
    lResult = bmp.CreateFromBITMAPINFO(hDib)
     
    IF lResult
    * make sure the target folder is valid 
    * uncomment one or more lines with savetofile 
    *!*        bmp.savetofile("c:\temp\tmp.jpg")
    *!*        bmp.savetofile("c:\temp\tmp.gif")
    *!*        bmp.savetofile("c:\temp\tmp.bmp")
    *!*        bmp.savetofile("c:\temp\tmp.tif")
    *!*        bmp.savetofile("c:\temp\tmp.png")
    ENDIF
     
    = CloseClipboard()
    * end of main
     
    PROCEDURE decl
        DECLARE INTEGER CloseClipboard IN user32 
        DECLARE INTEGER OpenClipboard IN user32 INTEGER hwnd 
        DECLARE INTEGER GetClipboardData IN user32 INTEGER uFormat
     
        DECLARE INTEGER IsClipboardFormatAvailable IN user32;
            INTEGER wFormat
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    1358 bytes  
    Created: 2004-12-05 15:02:35  
    Modified: 2004-12-05 16:06:00  
    Visits in 7 days: 198  
    Listed functions:
    CloseClipboard
    GetClipboardData
    IsClipboardFormatAvailable
    OpenClipboard
    Printer friendly API declarations
    My comment:
    When an image is copied, most likely it creates on the clipboard at least three different blocks of data:
    - Bitmap handle (CF_BITMAP)
    - BITMAPINFO structure (CF_DIB)
    - BITMAPV5HEADER structure (CF_DIBV5)

    This code above retrieves data in CF_DIB format from the clipboard and passes it to the GdipCreateBitmapFromGdiDib function to create an instance of GDI+ bitmap object. This newly created object can be saved to a file, printed or painted on a window.

    The GetClipboardData returns a pointer to a memory object containing a BITMAPINFO structure followed by the bitmap bits.

    There is a simplification in the way the code treats the BITMAPINFO data. For some display resolutions, like 1, 4, 8 and rarely 16 bits per pixel, the BITMAPINFO structure may contain a color table. If you are able to use GDI+ and Visual FoxPro, most likely your display resolution does not require a presence of such color table in the BITMAPINFO structure. That is how this structure is believed to contain only 40 bytes occupied by BITMAPINFOHEADER data.

    * * *
    Same way the GetClipboardData call with CF_BITMAP as input parameter can retrieve a bitmap handle. This handle then can be passed to the GdipCreateBitmapFromHBITMAP function to create an instance of GDI+ bitmap object. This newly created object can be saved to a file, printed or painted on a window.
    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 (72.44.48.122)
    5 sec.Function: 'GetClipboardOwner'
    2.11 hrs.Function: 'IsWindow'
    Function group: 'Window'
    6.01 hrs.Example: 'Displaying system dialog that selects a folder'
     Function: 'GdipFillPieI'
    7.04 hrs.Function: 'SetBkMode'
    Function group: 'Painting and Drawing'
     Example: 'A procedure for setting file times'
     Function: 'SQLExecDirect'
    Function group: 'ODBC API'
    9.59 hrs.Function: 'GdipTranslateMatrix'
     Function: 'WTSSendMessage'
    9.71 hrs.Example: 'Obtaining some properties for the Windows desktop using the GetWindowPlacement function'
    Google
    Advertise here!