Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to register custom Event Log source
How to Start a Process as Another User (NT/XP/2K)
Placing an arbitrary rectangular area of main VFP window on the Clipboard
Reading data from INI files
Using NetWkstaTransportEnum to obtain MAC Address of remote server
How to create a desktop shortcut (shell link)
How to retrieve adapter information for the local computer (including MAC address)
Obtaining addresses for the adapters on the local computer (Win XP/2003/Vista)
Programmatically removing submenus from VFP main menu
Quering a waveform-audio input device
Winsock: retrieving information about available transport protocols
Enumerating devices installed on the local machine
How to display advanced Task Dialog (Vista)
How to generate GUID values
How to run FoxPro application under different user name (impersonating user)
Retrieving IP statistics for the computer
System and Local Time values
Winsock: how to retrieve the protocol information corresponding to a protocol name
Winsock: resolving an address to a host name
Converting a hexadecimal string to an integer
Finding out if the current user is the Guest account
PocketPC: custom RAPI class for executing routines on remote Windows CE device
Retrieving the name of the default printer for the current user on the local computer (Win NT/XP)
Using the CreateFile
How to obtain Content-Type value for a file type from the System Registry

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 below retrieves list of content-type values with corresponding file extensions from HKEY_CLASSES_ROOT\MIME\Database\Content Type. It links, for example, text/html to .htm file type.

Content-type value for a particular file type (reversed lookup) can be obtained from corresponding sub-key of HKEY_CLASSES_ROOT. For example, for .html read values of HKEY_CLASSES_ROOT\.html key.

See also:
  • How to find an application associated with the file name
  • Displaying the associated icons and descriptions for files and folders
  • How to view system icons for the classes installed on the local machine

  •  
    DO decl
     
    #DEFINE HKEY_CLASSES_ROOT  0x80000000
    #DEFINE HKEY_CURRENT_USER  0x80000001
    #DEFINE HKEY_LOCAL_MACHINE 0x80000002
    #DEFINE ERROR_SUCCESS 0
    #DEFINE KEY_ALL_ACCESS 0xf003f
    #DEFINE KEY_READ 0x20019
    #DEFINE KeyMIME "MIME\Database\Content Type"
    #DEFINE KeyClasses "SOFTWARE\Classes"
    #DEFINE KeyExtension "Extension"
    #DEFINE KeyCLSID "CLSID"
     
    CREATE CURSOR cs (ext C(10), CLSID C(50), contenttype C(50),;
        checktype C(50), filetype1 C(100), filetype2 C(100))
     
    LOCAL hKey, nResult, nIndex, cBuffer, nResult, hSubkey,;
        cExtension, cCLSID, cContentType, cFiletype, cFiletype2
     
    hKey=0
    nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT, KeyMIME, 0,;
        KEY_READ, @hKey)
     
    IF nResult <> ERROR_SUCCESS
        ? "RegOpenKeyEx failed with error code: " + nResult
        RETURN
    ENDIF
     
    * enumerating subkeys of
    * HKEY_CLASSES_ROOT\MIME\Database\Content Type
    nIndex=0
    DO WHILE .T.
        cBuffer = REPLICATE(CHR(0), 512)
        nResult = RegEnumKey(hKey, nIndex, @cBuffer, Len(cBuffer))
        IF nResult <> ERROR_SUCCESS
            EXIT
        ENDIF
     
        cBuffer = SUBSTR(cBuffer, 1, AT(Chr(0),cBuffer)-1)
        INSERT INTO cs (contenttype) VALUES (m.cBuffer)
     
        hSubkey = 0
        IF RegOpenKeyEx(hKey, cBuffer, 0,;
            KEY_READ, @hSubkey) = ERROR_SUCCESS
     
            cExtension = GetKeyValue(hSubkey, KeyExtension)
            cCLSID = GetKeyValue(hSubkey, KeyCLSID)
     
            REPLACE cs.ext WITH cExtension, cs.CLSID WITH m.cCLSID
            = RegCloseKey(hSubkey)
        ENDIF
        nIndex = nIndex + 1
    ENDDO
    = RegCloseKey(hKey)
     
    * retrieving content type and file type values
    SELECT cs
    SCAN ALL FOR NOT EMPTY(cs.ext)
        cExtension = ALLTRIM(cs.ext)
     
        cContentType = GetContentType(m.cExtension)
        REPLACE checktype WITH m.cContentType
     
        cFiletype1 = GetDefaultKeyValue(HKEY_CLASSES_ROOT,;
            m.cExtension)
     
        IF EMPTY(cFiletype1)
            cFiletype2 = ""
        ELSE
            cFiletype2 = GetDefaultKeyValue(HKEY_LOCAL_MACHINE,;
                KeyClasses + "\" + m.cFiletype1)
        ENDIF
     
        REPLACE filetype1 WITH m.cFiletype1,;
            filetype2 WITH m.cFiletype2
    ENDSCAN
     
    SELECT cs
    GO TOP
    BROWSE NORMAL NOWAIT
    * end of main
     
    FUNCTION GetKeyValue(hKey, cValueName)
        LOCAL nIndex, cName, nNameSize, nType,;
            cBuffer, nBufsize, nResult
     
        STORE 0 TO nIndex, nType
        DO WHILE .T.
            STORE 4096 TO nNameSize, nBufsize
            STORE REPLICATE(CHR(0), nBufsize) TO cName, cBuffer
     
            nResult = RegEnumValue(hKey, nIndex, @cName, @nNameSize,;
                0, @nType, @cBuffer, @nBufsize)
     
            IF nResult = ERROR_SUCCESS
                cName = SUBSTR(cName, 1, AT(CHR(0), cName)-1)
                IF UPPER(ALLTRIM(cValueName)) == UPPER(ALLTRIM(cName))
                    RETURN SUBSTR(cBuffer, 1, AT(CHR(0), cBuffer)-1)
                ENDIF
            ELSE
                RETURN ""
            ENDIF
            nIndex = nIndex + 1
        ENDDO
    RETURN ""
     
    FUNCTION GetDefaultKeyValue(hParent, cSubkey)
        LOCAL nResult, hKey, cValue
     
        IF RegOpenKeyEx(hParent,;
            m.cSubkey, 0, KEY_READ, @hKey) = 0
            cValue = GetKeyValue(hKey, "")
            = RegCloseKey(m.hKey)
        ELSE
            cValue = ""
        ENDIF
    RETURN m.cValue
     
    FUNCTION GetContentType(cExt)
        LOCAL hKey, cContentType, nResult
        nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT,;
            m.cExt, 0, KEY_READ, @hKey)
        IF nResult <> 0
            RETURN ""
        ENDIF
        cContentType = GetKeyValue(hKey, "Content Type")
        = RegCloseKey(hKey)
    RETURN m.cContentType
     
    PROCEDURE decl
        DECLARE INTEGER RegCloseKey IN advapi32 INTEGER hKey
     
        DECLARE INTEGER RegOpenKeyEx IN advapi32;
            INTEGER hKey, STRING lpSubKey, INTEGER ulOptions,;
            INTEGER samDesired, INTEGER @phkResult
     
        DECLARE INTEGER RegEnumValue IN advapi32;
            INTEGER hKey, INTEGER dwIndex, STRING @lpValueName,;
            INTEGER @lpcValueName, INTEGER lpReserved, INTEGER @lpType,;
            STRING @lpData, INTEGER @lpcbData
     
        DECLARE INTEGER RegEnumKey IN advapi32;
            INTEGER hKey, INTEGER dwIndex, STRING @lpName,;
            INTEGER cchName
     
     
     

    User rating: 0/10 (0 votes)
    Rate this code sample:
    • ~
    3734 bytes  
    Created: 2004-09-03 08:23:41  
    Modified: 2010-05-13 09:58:39  
    Visits in 7 days: 93  
    Listed functions:
    RegCloseKey
    RegEnumKey
    RegEnumValue
    RegOpenKeyEx
    Printer friendly API declarations
    My comment:
    Code similar to the above I used in FoxPro SendEmail class. To assemble multi-part email message, you need to know content-type value for each file attachment to encode the file as well as to add this value as SMTP header.

    Same should be true for files transferred to remote server through HTTP POST requests.

    * * *
    Question: how to obtain file type, the one Explorer displays in Type column, for a given extension?



    Solution:

    Step 1. Read default value for HKEY_CLASSES_ROOT\.vbw



    Step 2. Read default value for HKEY_CLASSES_ROOT\VisualBasic.VBWFile or for HKEY_LOCAL_MACHINE\SOFTWARE\Classes\VisualBasic.VBWFile


    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.166.175)
    6 sec.Example: 'Accessing Adobe Reader 7.0 main menu from VFP application'
    6.12 min.Example: 'Determining if an Active Network Connection is Available'
    55.28 min.Example: 'Comparing file times'
    55.32 min.Links
    Page 3
    55.37 min.Function: 'GetThreadPriority'
    Function group: 'Process and Thread'
    5.97 hrs.Function: 'WTSFreeMemory'
    Function group: 'Terminal Services'
     Example: 'Copying picture of the active form to the Clipboard using Enhanced Metafile API functions'
     Example: 'Displaying animated images on FoxPro form with BitBlt and StretchBlt functions'
    6.85 hrs.Function: 'CeSetFilePointer'
    Function group: 'Remote Application Programming (RAPI)'
     Function: 'GdipDeletePen'
    Function group: 'GDI+ Pen'
    Google
    Advertise here!