Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Displaying animated images on FoxPro form with BitBlt and StretchBlt functions
FindText -- the hopeless and useless Common Dialog
How to initiate System shutdown
Setting properties of the window: caption and user-defined value
Shortcut Menu Class
The original LoadPicture() function in VFP returns valid handles to bitmaps, icons, cursors, and metafiles
Using custom Simple MapiSendMail class
Enumerating the subkeys for a given registry key
GDI+: printing vertical text on VFP reports via generated images (VFP8)
How to enumerate sessions and processes on a specified terminal server
How to play a waveform sound (a WAV file in particular)
How to retrieve network parameters for the local computer (including Host name, Domain name, and DNS Server)
How to retrieve the number of print jobs queued for the printer
How to write and read Window Properties for the specified window
Monitoring changes occurring within a directory
Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
Retrieving information about the specified icon
Using the GradientFill function
Using the MessageBox Win32 function
Using the SystemParametersInfo function
How to delete all print jobs for a printer
How to enumerate cookies and URL History entries in the cache of the local computer
Setting the mouse capture to the specified window
Testing Clipboard functions: emptying the clipboard
Obtaining physical parameters for a drive: sectors, clusters, cylinders...

User rating: 10/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
Before you begin:
The code shows how to obtain number of cylinders, tracks, sectors and clusters for a given device like HD, floppy or CD.

See also:
  • Displaying the drive type value
  • Basic Volume information
  • Setting the volume label
  • Disk in drive A:
  •  
    DO decl
    DO GetDeviceInfo_1
    DO GetDeviceInfo_2
    * end of main
     
    PROCEDURE GetDeviceInfo_1
        STORE 0 TO nSectorsPerCluster, nBytesPerSector,;
            nFreeClusters, nTotalClusters
     
        LOCAL lcRootName, nTotalSize
        lcRootName = "C:\"
        *lcRootName = "A:\"  && a way to test if a disk inserted
     
        = GetDiskFreeSpace(lcRootName, @nSectorsPerCluster,;
            @nBytesPerSector, @nFreeClusters, @nTotalClusters)
     
        ?
        ? "*** Returned by GetDiskFreeSpace:"
        ? "Device name:", lcRootName
        ? "Total clusters:", nTotalClusters
        ? "Free clusters:", nFreeClusters
        ? "Sectors per cluster:", nSectorsPerCluster
        ? "Bytes per sector:", nBytesPerSector
     
        nTotalSize = nTotalClusters * nSectorsPerCluster * nBytesPerSector
        ? "Total size: ", TRANSFORM(nTotalSize, "999,999,999,999")
     
    PROCEDURE GetDeviceInfo_2
    #DEFINE FILE_SHARE_READ   1
    #DEFINE FILE_SHARE_WRITE  2
    #DEFINE OPEN_EXISTING     3
    #DEFINE INVALID_HANDLE_VALUE -1
    #DEFINE IOCTL_DISK_GET_DRIVE_GEOMETRY 0x70000
    #DEFINE ERROR_INSUFFICIENT_BUFFER 122
    #DEFINE MAX_DWORD 0x100000000
     
        LOCAL cDrive, hDevice
        cDrive = "\\.\PhysicalDrive0"
    *    cDrive = "\\.\c:"
     
        hDevice = CreateFile(m.cDrive, 0,;
            BITOR(FILE_SHARE_READ, FILE_SHARE_WRITE),;
            0, OPEN_EXISTING, 0, 0)
     
        IF hDevice = INVALID_HANDLE_VALUE
            ? "Error: INVALID_HANDLE_VALUE"
            RETURN
        ENDIF
     
    *|typedef struct _DISK_GEOMETRY {
    *|  LARGE_INTEGER Cylinders;  0:8
    *|  MEDIA_TYPE MediaType;     8:4
    *|  DWORD TracksPerCylinder; 12:4
    *|  DWORD SectorsPerTrack;   16:4
    *|  DWORD BytesPerSector;    20:4
    *|} DISK_GEOMETRY; total bytes: 24
    #DEFINE DISK_GEOMETRY_SIZE 24
     
        LOCAL cBuffer, nBufsize, nCylinders, nMediaType, nTracksPerCyl,;
            nSecPerTrack, nBytesPerSec, nTotalSize
        cBuffer = REPLICATE(CHR(0), DISK_GEOMETRY_SIZE)
        nBufsize=0
     
        = DeviceIoControl(m.hDevice, IOCTL_DISK_GET_DRIVE_GEOMETRY,;
            Null, 0, @cBuffer, LEN(cBuffer), @nBufsize, 0)
     
        nCylinders = GetLongInt(SUBSTR(cBuffer,1,4), SUBSTR(cBuffer,5,4))
        nMediaType = buf2dword(SUBSTR(cBuffer,9,4))
        nTracksPerCyl = buf2dword(SUBSTR(cBuffer,13,4))
        nSecPerTrack =  buf2dword(SUBSTR(cBuffer,17,4))
        nBytesPerSec = buf2dword(SUBSTR(cBuffer,21,4))
        ?
        ? "*** Returned by DeviceIoControl:"
        ? "Device name:", cDrive
        ? "Cylinders:", nCylinders
        ? "Media Type:", nMediaType
        ? "Tracks per cylinder:", nTracksPerCyl
        ? "Sector per track:", nSecPerTrack
        ? "Bytes per sector:", nBytesPerSec
     
        nTotalSize = nCylinders * nTracksPerCyl * nSecPerTrack *;
            nBytesPerSec
        ? "Total size:", TRANSFORM(nTotalSize, "999,999,999,999")
     
        = CloseHandle(hDevice)
     
    PROCEDURE decl
        DECLARE INTEGER GetDiskFreeSpace IN kernel32;
            STRING lpRootPathName, INTEGER @lpSectorsPerCluster,;
            INTEGER @lpBytesPerSector, INTEGER @lpNumberOfFreeClusters,;
            INTEGER @lpTotalNumberOfClusters
     
        DECLARE INTEGER DeviceIoControl IN kernel32;
            INTEGER hDevice, INTEGER dwIoControlCode, STRING @lpInBuffer,;
            INTEGER nInBufferSize, STRING @lpOutBuffer, INTEGER nOutBufferSize,;
            INTEGER @lpBytesReturned, INTEGER lpOverlapped
     
        DECLARE INTEGER CreateFile IN kernel32;
            STRING lpFileName, INTEGER dwAccess, INTEGER dwShareMode,;
            INTEGER lpSecurityAttr, INTEGER dwCreationDisp,;
            INTEGER dwFlagsAndAttr, INTEGER hTemplateFile
     
        DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
        DECLARE INTEGER GetLastError IN kernel32
     
    FUNCTION GetLongInt(Lo, Hi)
    #DEFINE MAX_DWORD 0x100000000
        IF VARTYPE(m.Lo)="C"
            Lo = buf2dword(m.Lo)
        ENDIF
        IF VARTYPE(m.Hi) = "C"
            Hi = buf2dword(m.Hi)
        ENDIF
    RETURN m.Hi * MAX_DWORD + m.Lo
     
    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)
     
     
     

    User rating: 10/10 (1 votes)
    Rate this code sample:
    • ~
    3753 bytes  
    Created: 2001-08-13 12:00:00  
    Modified: 2009-02-04 14:22:45  
    Visits in 7 days: 71  
    Listed functions:
    CloseHandle
    CreateFile
    DeviceIoControl
    GetDiskFreeSpace
    GetLastError
    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:
    sridhar | 2007-02-09 06:27:54
    Is it possible to get the serial number of the drive with DeviceIoControl ?

    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 (107.21.156.140)
    7.65 min.Example: 'Creating a folder'
    7.75 min.Example: 'How to copy the image of a form to the Clipboard using Bitmap API functions'
    14.1 min.Example: 'Enumerating servers of the specified type (e.g. SQL Server) in the primary domain'
    14.15 min.Example: 'Saving HKEY_LOCAL_MACHINE\\Software\\ODBC Registry Entries to an XML file'
    14.2 min.Function: 'StretchBlt'
    1.47 hrs.
    Function group: 'Simple MAPI'
     Example: 'Retrieving the IP-to-physical address mapping table'
    2.5 hrs.Example: 'Enumerating Processes -- WinNT'
     Links
    Page 1
    4.46 hrs.Function: 'SetWindowRgn'
    Google
    Advertise here!