Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Using the IsWindowEnabled function
Downloading files from the FTP server using InternetReadFile
Storing screen shot of a form to bitmap file
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Displaying hypertext links with the SysLink control (VFP9, Comctl32.dll)
How to enumerate, add and delete shares on the local computer (WinNT/XP)
Initiating Inet connection using a modem
Scanning a hierarchy of child windows down from the Windows Desktop
Adding and deleting User Accounts
How to display a dialog box with which the user can add a data source (DSN)
Locking mouse and keyboard input for the VFP application
Obtaining list of tables stored in an ODBC Data Source
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Retrieving names for the registered clipboard formats
Starting an external application in VFP using WinExec
String representation for disk or memory capacity
Winsock: retrieving the host information corresponding to a network address
Displaying standard progress dialog box when copying files
Enumerating print processors and supporting data types installed on the specified server
How to browse and connect to printers on a network (WinNT)
How to delete IE cookies, clear IE history and delete files in Temporary Internet Files directory
How to retrieve version information for the specified file
Retrieveing information about the active window (even if it is not owned by the calling process)
Retrieving the command line for the VFP session
Enumerating printer drivers installed

User rating: 9/10 (1 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:

See also:
  • Enumerating locally installed printers
  • Enumerating the print processors and supporting data types installed on the specified server
  • Enumerating print jobs and retrieving information for default printer
  • How to retrieve number of print jobs that have been queued for the printer
  • Enumerating the ports that are available for printing on a specified server

  •  
    #DEFINE GMEM_FIXED 0
    DO declare
     
    *|typedef struct _DRIVER_INFO_2 { 
    *|  DWORD  cVersion;     0:4
    *|  LPTSTR pName;        4:4
    *|  LPTSTR pEnvironment; 8:4
    *|  LPTSTR pDriverPath;  12:4
    *|  LPTSTR pDataFile;    16:4
    *|  LPTSTR pConfigFile;  20:4
    *|} DRIVER_INFO_2, *PDRIVER_INFO_2; -> 24 bytes
     
    #DEFINE DRIVER_INFO_SIZE 24
     
    PRIVATE hBuffer, nBufsize, cBuffer, cInfo
     
    nBufsize = 16384
    hBuffer = GlobalAlloc(GMEM_FIXED, nBufsize)
     
    LOCAL lcServer, lnResult, lnReturned, lnCount
    STORE 0 TO lnReturned, lnIndex, lnCount
     
    * use Null for local computer or a valid server name 
    * e.g. "\\MYSERVER"
    lcServer = Null
    lnResult = EnumPrinterDrivers(lcServer,;
        Null, 2, hBuffer, nBufsize,;
        @lnReturned, @lnCount)
     
    IF lnResult = 0
        ? "Error code:", GetLastError()
        = GlobalFree(hBuffer)
        RETURN
    ENDIF
     
    cBuffer = REPLICATE(CHR(0), nBufsize)
    = Mem2Str(@cBuffer, hBuffer, nBufsize)
     
    * cursor for storing driver data
    CREATE CURSOR csDrvList (;
        ver I, drvname C(50),;
        envname C(20),;
        drvpath C(200),;
        drvfile C(200), cfgfile C(200))
     
    FOR lnIndex=0 TO lnCount-1
     
        cInfo = SUBSTR(cBuffer,;
            lnIndex * DRIVER_INFO_SIZE+1,;
            DRIVER_INFO_SIZE)
     
        INSERT INTO csDrvList;
        VALUES (mw(1), ms(5), ms(9),;
            ms(13), ms(17), ms(21))
     
    ENDFOR
     
    = GlobalFree(hBuffer)
     
    IF USED("csDrvList")
        GO TOP
        EDIT NORMAL NOWAIT
    ENDIF
    * end of main
     
    FUNCTION mw(lnOffs As Number)
    RETURN buf2dword(SUBSTR(cInfo, lnOffs, 4))
     
    FUNCTION ms(lnOffs As Number)
    RETURN GetMemStr(buf2dword(SUBSTR(cInfo, lnOffs, 4)))
     
    FUNCTION GetMemStr(lnAddr As Number)
        IF lnAddr = 0
            RETURN ""
        ENDIF
     
        LOCAL lnOffs, lcResult, ch
        lnOffs = lnAddr - hBuffer + 1
        lcResult = ""
     
        DO WHILE lnOffs < nBufsize
            ch = SUBSTR(cBuffer, lnOffs,1)
            IF ch = Chr(0)
                EXIT
            ELSE
                lcResult = lcResult + ch
            ENDIF
            lnOffs = lnOffs + 1
        ENDDO
    RETURN lcResult
     
    FUNCTION buf2dword (lcBuffer As Character)
    RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
        BitLShift(Asc(SUBSTR(lcBuffer, 2,1)), 8) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 3,1)), 16) +;
        BitLShift(Asc(SUBSTR(lcBuffer, 4,1)), 24)
     
    PROCEDURE declare
        DECLARE INTEGER EnumPrinterDrivers IN winspool.drv;
            STRING pName, STRING pEnvironment,;
            LONG Lvl, INTEGER pDrvInfo,;
            INTEGER cbBuf, INTEGER @pcbNeeded,;
            INTEGER @pcReturned
     
        DECLARE INTEGER GetLastError IN kernel32
        DECLARE INTEGER GlobalFree IN kernel32 INTEGER hMem
     
        DECLARE INTEGER GlobalAlloc IN kernel32;
            INTEGER wFlags, INTEGER dwBytes
     
        DECLARE RtlMoveMemory IN kernel32 As Mem2Str;
            STRING @Dest, INTEGER Src,;
            INTEGER nLength
     

    User rating: 9/10 (1 votes)
    Rate this code sample:
    • ~
    2587 bytes  
    Created: 2001-08-01 12:00:00  
    Modified: 2010-08-05 09:31:03  
    Visits in 7 days: 117  
    Listed functions:
    EnumPrinterDrivers
    GetLastError
    GlobalAlloc
    GlobalFree
    Printer friendly API declarations
    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)
    12.88 hrs.Example: 'Memory usage info for current VFP session (WinNT only)'
    13.1 hrs.Example: 'How to create non-blocking Winsock server'
     Function: 'RegisterRawInputDevices'
    14.82 hrs.
    Function group: 'Menu'
     Example: 'Accessing examples contained in this reference from a VFP application'
    18.07 hrs.Example: 'How to print picture stored in enhanced-format metafile (*.emf)'
     Function: 'GetShortPathName'
    18.55 hrs.Function: 'GdipGetImageHorizontalResolution'
    Function group: 'GDI+ Image'
     Function: 'SwitchToThisWindow'
    Function group: 'Window'
    18.96 hrs.Example: 'How to display the Properties dialog box for a file (ShellExecuteEx)'
    Google
    Advertise here!