Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Pocket PC: Folder Viewer
Storing content of the Clipboard to a bitmap file
Winsock: initializing the service in the VFP application
Creating an Open dialog box to specify the drive, directory, and name of a file to open (Shell32 version)
Disconnecting USB Mass Storage Device programmatically
Displaying icons in the system tray (VFP9)
Listing child windows for the Windows desktop
Running a regular FoxPro form while main VFP window is minimized
Winsock: reading email messages (POP3, port 110)
Winsock: retrieving directory listing from an FTP server using passive data connection (FTP, port 21)
Disabling mouse and keyboard input for the main VFP window (with the app still running)
GDI+: how to make VFP controls visually shake and shudder
How to change the name and the size of the font in the MessageBox dialog
How to make a VFP form fading out when released (GDI+ version)
How to set Creation Date/Time for a folder (WinNT)
Retrieveing general information about the driver and data source associated with an ODBC connection
URL: splitting into its component parts
GDI+: Scrolling through large image using the mouse
Monitoring changes in a directory
Obtaining physical parameters for a drive: sectors, clusters, cylinders...
Reading and setting Environment variables
Writing entries to custom Event Log
Displaying standard progress dialog box when copying files
Enumerating network resources
Pocket PC: base class

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 class is used as a base class for several custom RAPI classes created to access objects stored on Pocket PC:

  • System Registry
  • Object Store Databases
  • Files and folders
  • Executing routines

    See also:
  • FoxPro Advisor article: Access a Pocket PC from Visual FoxPro
  • FoxPro Advisor article: Access a Palm OS PDA from Visual FoxPro
  • ****************************************************
    * Pocket PC: base RAPI class
    ****************************************************
    DEFINE CLASS Trapi As Custom
    #DEFINE RAPIINIT_SIZE  12
    #DEFINE WAIT_OBJECT_0  0
        majorver=0
        minorver=0
        buildno=0
        aclinestatus=0
        batteryflag=0
        batterylifepercent=0
        storesize=0
        freesize=0
        phmemtotal=0
        phmemavail=0
        cputype=0
        cpulevel=0
        cpurevision=0
        connected=.F.
    
    PROCEDURE Init
        THIS.decl
        THIS.InitRapi
    
    PROCEDURE InitRapi
        THIS.UninitRapi
    
        LOCAL cBuffer, hEvent
        cBuffer = PADR(CHR(RAPIINIT_SIZE), RAPIINIT_SIZE, CHR(0))
    
        = CeRapiInitEx(@cBuffer)
        hEvent = buf2dword(SUBSTR(cBuffer,5,4))
    
        IF WaitForSingleObject(hEvent,2000) = WAIT_OBJECT_0
            THIS.connected = .T.
        ELSE
            THIS.UninitRapi
        ENDIF
    RETURN THIS.connected
    
    PROCEDURE UninitRapi
        = CeRapiUninit()
        THIS.connected = .F.
    
    PROCEDURE Destroy
        THIS.UninitRapi
    
    PROCEDURE GetSysInfo
        THIS.GetVersion
        THIS.GetPowerStatus
        THIS.GetStoreSize
        THIS.GetGlobalMemoryStatus
        THIS.GetCPUInfo
    
    PROCEDURE GetVersion
    #DEFINE CEOSVERSIONINFO_SIZE 276
        LOCAL cBuffer, hBuffer
        cBuffer = PADR(num2dword(CEOSVERSIONINFO_SIZE),;
            CEOSVERSIONINFO_SIZE, Chr(0))
        = CeGetVersionEx(@cBuffer)
        THIS.majorver = buf2dword(SUBSTR(cBuffer, 5,4))
        THIS.minorver = buf2dword(SUBSTR(cBuffer, 9,4))
        THIS.buildno = buf2dword(SUBSTR(cBuffer, 13,4))
    
    FUNCTION GetSpecialFolderPath(nFolder)
        LOCAL nBufsize, cBuffer
        nBufsize = 250
        cBuffer = REPLICATE(CHR(0), nBufsize*2)
        nBufsize = CeGetSpecialFolderPath(nFolder, nBufsize, @cBuffer)
    RETURN STRCONV(SUBSTR(cBuffer,1,nBufsize*2),6)
    
    PROCEDURE GetPowerStatus
    #DEFINE SYSTEM_POWER_STATUS 24
        LOCAL cBuffer
        cBuffer = REPLICATE(CHR(0), SYSTEM_POWER_STATUS)
        = CeGetSystemPowerStatusEx(@cBuffer, 0)
        THIS.aclinestatus = ASC(SUBSTR(cBuffer,1,1))
        THIS.batteryflag = ASC(SUBSTR(cBuffer,2,1))
        THIS.batterylifepercent = ASC(SUBSTR(cBuffer,3,1))
    
    PROCEDURE GetStoreSize
    #DEFINE STORE_INFORMATION_SIZE 8
        LOCAL cBuffer
        cBuffer = Repli(Chr(0), STORE_INFORMATION_SIZE)
        = CeGetStoreInformation(@cBuffer)
        THIS.storesize = buf2dword(SUBSTR(cBuffer, 1,4))
        THIS.freesize = buf2dword(SUBSTR(cBuffer, 5,4))
    
    PROCEDURE GetGlobalMemoryStatus
    #DEFINE MEMORYSTATUS_SIZE 32
        LOCAL cBuffer
        cBuffer = PADR(CHR(MEMORYSTATUS_SIZE), MEMORYSTATUS_SIZE, CHR(0))
        = CeGlobalMemoryStatus(@cBuffer)
        THIS.phmemtotal = buf2dword(SUBSTR(cBuffer, 9,4))
        THIS.phmemavail = buf2dword(SUBSTR(cBuffer, 13,4))
    
    PROCEDURE GetCPUInfo
    #DEFINE SYSTEM_INFO_SIZE 36
        LOCAL cBuffer
        cBuffer = PADR(CHR(SYSTEM_INFO_SIZE), SYSTEM_INFO_SIZE, CHR(0))
        = CeGetSystemInfo(@cBuffer)
        THIS.cputype = buf2dword(SUBSTR(cBuffer, 25,4))
        THIS.cpulevel = buf2word(SUBSTR(cBuffer, 33,2))
        THIS.cpurevision = buf2word(SUBSTR(cBuffer, 35,2))
    
    PROTECTED PROCEDURE decl
        DECLARE INTEGER LocalFree IN kernel32 INTEGER hMem
        DECLARE INTEGER CeRapiUninit IN rapi
        DECLARE INTEGER CeGetLastError IN rapi
        DECLARE INTEGER CeRapiInitEx IN rapi STRING @pRapiInit
        DECLARE INTEGER CeCloseHandle IN rapi INTEGER hObject
        DECLARE INTEGER CeGetVersionEx IN rapi STRING @lpVersionInfo
        DECLARE INTEGER CeGetStoreInformation IN rapi STRING @lpsi
        DECLARE CeGlobalMemoryStatus IN rapi STRING @lpmst
        DECLARE CeGetSystemInfo IN rapi STRING @lpSystemInfo
    
        DECLARE INTEGER CeGetSystemPowerStatusEx IN rapi;
            STRING @pstatus, INTEGER fUpdate
    
        DECLARE INTEGER CeGetSpecialFolderPath IN rapi;
            INTEGER nFolder, INTEGER nBufferLength, STRING @lpBuffer
    
        DECLARE INTEGER LocalAlloc IN kernel32;
            INTEGER uFlags, INTEGER uBytes
    
        DECLARE RtlMoveMemory IN kernel32 As StrToMem;
            INTEGER Dest, STRING @Src, INTEGER nLength
    
        DECLARE RtlMoveMemory IN kernel32 As MemToStr;
            STRING @dest, INTEGER src, INTEGER nLength
    
        DECLARE INTEGER WaitForSingleObject IN kernel32;
            INTEGER hHandle, INTEGER dwMilliseconds
    ENDDEFINE
    
    *************************** static members ***************************
    FUNCTION buf2dword(lcBuffer)
    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)
    
    FUNCTION buf2word(lcBuffer)
    RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
           Asc(SUBSTR(lcBuffer, 2,1)) * 256
    
    FUNCTION num2dword(lnValue)
    #DEFINE m0  256
    #DEFINE m1  65536
    #DEFINE m2  16777216
        IF lnValue < 0
            lnValue = 0x100000000 + lnValue
        ENDIF
        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)
    
    FUNCTION num2word(lnValue)
    RETURN Chr(MOD(m.lnValue,256)) + CHR(INT(m.lnValue/256))
    
    FUNCTION ToUnicode(cStr)
    RETURN STRCONV(m.cStr+CHR(0), 5)
    
    FUNCTION FromUnicode(cStr)
    RETURN STRCONV(m.cStr, 6)
    
    
    

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    4838 bytes  
    Created: 2004-06-20 14:23:24  
    Modified: 2011-12-10 09:20:22  
    Visits in 7 days: 21  
    Listed functions:
    CeCloseHandle
    CeGetLastError
    CeGetSpecialFolderPath
    CeGetStoreInformation
    CeGetSystemInfo
    CeGetSystemPowerStatusEx
    CeGetVersionEx
    CeGlobalMemoryStatus
    CeRapiInitEx
    CeRapiUninit
    LocalAlloc
    LocalFree
    WaitForSingleObject
    Printer friendly API declarations
    My comment:


    #kwd: sln_pocketpc.
    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-2015 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.166.122.69)
    15 sec.Example: 'Displaying system dialog that selects a folder'
    38 sec.Function: 'ReadFile'
    Function group: 'File Management'
    1.87 min.Function: 'GetDefaultPrinter'
    Function group: 'Printing and Print Spooler'
    Google
    Advertise here!