VB Code:
  1. Private Const MAX_PATH As Long = 260
  2. Private Const HKEY_CLASSES_ROOT As Long = &H80000000
  3. Private Const ERROR_SUCCESS As Long = 0
  4. Private Const vbDot As Long = 46
  5. Private Const SHGFI_USEFILEATTRIBUTES As Long = &H10
  6. Private Const SHGFI_TYPENAME As Long = &H400
  7. Private Const LB_SETTABSTOPS As Long = &H192
  8.  
  9. Private Type FILETIME
  10.    dwLowDateTime As Long
  11.    dwHighDateTime As Long
  12. End Type
  13.  
  14. Private Type SHFILEINFO
  15.    hIcon As Long
  16.    iIcon As Long
  17.    dwAttributes As Long
  18.    szDisplayName As String * MAX_PATH
  19.    szTypeName As String * 80
  20. End Type
  21.  
  22. Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As FILETIME) As Long
  23. Private Declare Function SHGetFileInfo Lib "shell32" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
  24. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  25.  
  26. Private Sub GetAssociatedFileListing()
  27.  
  28.    Dim dwIndex As Long
  29.    Dim sTypeName As String
  30.    Dim sSubkey As String * MAX_PATH
  31.    Dim sClass As String * MAX_PATH
  32.    Dim ft As FILETIME
  33.    
  34.    Do While RegEnumKeyEx(HKEY_CLASSES_ROOT, _
  35.                          dwIndex, _
  36.                          sSubkey, _
  37.                          MAX_PATH, _
  38.                          0, sClass, _
  39.                          MAX_PATH, ft) = ERROR_SUCCESS
  40.      
  41.       If Asc(sSubkey) = vbDot Then
  42.          
  43.         'Pass the returned string to get the file type
  44.          sTypeName = GetFileType(sSubkey)
  45.            
  46.          If Len(sTypeName) > 0 Then
  47.             List1.AddItem TrimNull(sSubkey) & vbTab & sTypeName
  48.          End If            
  49.       End If
  50.       dwIndex = dwIndex + 1  
  51.    Loop
  52. End Sub
  53.  
  54. Private Function GetFileType(sFile As String) As String
  55.  
  56.   'If successful returns the specified file's
  57.   'typename, returns an empty string otherwise.
  58.   'sFile does not have to exist and can be
  59.   'just a file extension.
  60.    Dim sfi As SHFILEINFO
  61.  
  62.    If SHGetFileInfo(sFile, 0&, _
  63.                     sfi, Len(sfi), _
  64.                     SHGFI_TYPENAME Or SHGFI_USEFILEATTRIBUTES) Then
  65.       GetFileType = TrimNull(sfi.szTypeName)
  66.    End If
  67.  
  68. End Function
  69.  
  70. Private Function TrimNull(startstr As String) As String
  71.  
  72.   'returns the string up to the first
  73.   'null, if present, or the passed string
  74.    Dim pos As Integer
  75.    
  76.    pos = InStr(startstr, Chr$(0))
  77.    
  78.    If pos Then
  79.       TrimNull = Left$(startstr, pos - 1)
  80.       Exit Function
  81.    End If
  82.  
  83.    TrimNull = startstr
  84.  
  85. End Function
  86.  
  87. Private Sub Command1_Click()
  88.    List1.Clear
  89.    Screen.MousePointer = vbHourglass  
  90.   'fill the listbox box with the file types and their extensions
  91.    Call GetAssociatedFileListing  
  92.    Screen.MousePointer = vbDefault  
  93.  
  94. End Sub