In case we can’t find the default icon we need to display the Windows icon. Here’s how:
No_Icon:
'No icon could be found so we use the normal windows icon
'This icon is held in shell32.dll in the
system directory, Icon 0
strDefaultIcon = Space(260)
lngStringLength = GetSystemDirectory(strDefaultIcon, 260)
strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "SHELL32.DLL"
lngIconNumber = 0
GoTo Draw_Icon
End Sub
The windows icon will be held in the file “SHELL32.DLL” which is in the system folder. So we get the system directory and use that (along with “SHELL32.DLL”) for the file name, then go back to “Draw_Icon”.
At this point I am just going to add an extra piece of code that will handle EXEs. This is because EXEs have no default icon but it’s probably not best to just show the windows icon. So lets use the icon that windows normally uses for EXEs:
Add this near the begging beneath “TempFileName = Right...” and above “lngError = RegOpenKey...”
If
LCase(TempFileName) = ".exe" Then
strDefaultIcon = Space(260)
lngStringLength = GetSystemDirectory(strDefaultIcon, 260)
strDefaultIcon = Left(strDefaultIcon, lngStringLength) & "SHELL32.DLL"
lngIconNumber = 2
GoTo Draw_Icon
End If
This code is just the same as for getting the windows icon, except we now want icon 2 instead of 0.
Comments