http://hashvb.earlsoft.co.uk/index.php?title=GetDefaultIcon&feed=atom&action=history
GetDefaultIcon - Revision history
2024-03-28T18:09:18Z
Revision history for this page on the wiki
MediaWiki 1.22.2
http://hashvb.earlsoft.co.uk/index.php?title=GetDefaultIcon&diff=2447&oldid=prev
Dee: Added the VB6 header
2006-08-17T09:42:57Z
<p>Added the VB6 header</p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 09:42, 17 August 2006</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{VB6}}</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Retrieves and draws default file icon for a given file name extension.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Retrieves and draws default file icon for a given file name extension.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Example usage:</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Example usage:</div></td></tr>
</table>
Dee
http://hashvb.earlsoft.co.uk/index.php?title=GetDefaultIcon&diff=2412&oldid=prev
Breadman: Get Default File Icon
2006-06-20T04:06:52Z
<p>Get Default File Icon</p>
<p><b>New page</b></p><div>Retrieves and draws default file icon for a given file name extension.<br />
Example usage:<br />
GetDefaultIcon "example.pdf", Picture1.hDC<br />
Put the following code in a module.<br />
<pre><br />
Option Explicit<br />
<br />
'API Constants<br />
Private Const HKEY_CLASSES_ROOT = &H80000000<br />
Private Const KEY_READ = &H20019 'To allow us to READ the registry keys<br />
<br />
'API Declarations<br />
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long<br />
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Any, lpcbData As Long) As Long<br />
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long<br />
Private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long<br />
Private Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hIcon As Long) As Long<br />
Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long<br />
Private Declare Function GetSystemDirectory Lib "kernel32.dll" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long<br />
<br />
<br />
Public Sub GetDefaultIcon(FileName As String, Picture_hDC As Long)<br />
'Parameters:<br />
'FileName: The extension of the filename, with the "." e.g .doc<br />
'Picture_hDC: The Handle to the device context of the Picture Box you want the icon<br />
'to be displayed on.<br />
'Example:<br />
'Call GetDefaultIcon(".doc",Picture1.hDC)<br />
<br />
Dim strTmpFile As String<br />
Dim lngError As Long<br />
Dim lngRegKeyHandle As Long<br />
Dim strProgramName As String<br />
Dim strDefaultIcon As String<br />
Dim lngStringLength As Long<br />
Dim lngIconNumber As Long<br />
Dim lngIcon As Long<br />
Dim intN As Integer<br />
<br />
strTmpFile = Right(FileName, Len(FileName) - InStrRev(FileName, ".") + 1)<br />
strDefaultIcon = Space(260)<br />
lngStringLength = GetSystemDirectory(strDefaultIcon, 260)<br />
strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "\SHELL32.DLL"<br />
<br />
Select Case LCase(strTmpFile)<br />
Case ".exe"<br />
lngIconNumber = 2<br />
GoTo Draw_Icon<br />
Case ".doc", ".rtf"<br />
lngIconNumber = 1<br />
GoTo Draw_Icon<br />
End Select<br />
<br />
lngError = RegOpenKey(HKEY_CLASSES_ROOT, strTmpFile, lngRegKeyHandle)<br />
If lngError Then GoTo No_Icon<br />
lngStringLength = 260<br />
strProgramName = Space$(260)<br />
lngError = RegQueryValueEx(lngRegKeyHandle, vbNullString, 0, 0, strProgramName, lngStringLength)<br />
If lngError Then<br />
lngError = RegCloseKey(lngRegKeyHandle)<br />
GoTo No_Icon<br />
End If<br />
lngError = RegCloseKey(lngRegKeyHandle)<br />
strProgramName = Left(strProgramName, lngStringLength - 1)<br />
lngError = RegOpenKey(HKEY_CLASSES_ROOT, strProgramName & "\DefaultIcon", lngRegKeyHandle)<br />
If lngError Then GoTo No_Icon<br />
lngStringLength = 260<br />
strDefaultIcon = Space$(260)<br />
lngError = RegQueryValueEx(lngRegKeyHandle, vbNullString, 0, 0, strDefaultIcon, lngStringLength)<br />
If lngError Then<br />
lngError = RegCloseKey(lngRegKeyHandle)<br />
GoTo No_Icon<br />
End If<br />
lngError = RegCloseKey(lngRegKeyHandle)<br />
strDefaultIcon = Trim$(Left(strDefaultIcon, lngStringLength - 1))<br />
<br />
intN = InStrRev(strDefaultIcon, ",")<br />
If intN < 1 Then GoTo No_Icon<br />
lngIconNumber = Trim$(Right(strDefaultIcon, Len(strDefaultIcon) - intN))<br />
strDefaultIcon = Trim$(Left(strDefaultIcon, intN - 1))<br />
<br />
Draw_Icon:<br />
lngIcon = ExtractIcon(App.hInstance, strDefaultIcon, lngIconNumber)<br />
If lngIcon = 1 Or lngIcon = 0 Then GoTo No_Icon<br />
lngError = DrawIcon(Picture_hDC, 0, 0, lngIcon)<br />
lngError = DestroyIcon(lngIcon)<br />
Exit Sub<br />
No_Icon:<br />
'No icon could be found so we use the normal windows icon<br />
'This icon is held in shell32.dll in the system directory, Icon 0<br />
strDefaultIcon = Space(260)<br />
lngStringLength = GetSystemDirectory(strDefaultIcon, 260)<br />
strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "\SHELL32.DLL"<br />
lngIconNumber = 0<br />
GoTo Draw_Icon<br />
End Sub<br />
</pre></div>
Breadman