So we now have the location of the default icon. There is just one problem with this, the icon may be stored in a .exe, .dll or .ico file. This is not as much of a problem as it may sound using the other group of three APIs that we declared at the beginning.
But we just need to do one thing first. The default icon it stored in the form of: “C:\BlahBlah\Blah.ico, 42
”. We just need to split the number up from the location
'Find the comma
intN = InStrRev(strDefaultIcon, ",")
'We MUST have an icon number and it will be after the ",": NO COMMA NO DEFAULT ICON
If intN < 1 Then
GoTo No_Icon
'What number is after the comma
lngIconNumber = Trim$(Right(strDefaultIcon, Len(strDefaultIcon) - intN))
'We only want whatever is before the comma in the file name
strDefaultIcon = Trim$(Left(strDefaultIcon, intN - 1))
So now we just need to do is draw the thing. This is where we need the “Device Context” (hDC) of our picture box:
Draw_Icon:
'Extract the Icon
lngIcon = ExtractIcon(App.hInstance, strDefaultIcon, lngIconNumber)
'if 1 or 0 then after all that the Icon could not be retrieved
If lngIcon = 1 Or lngIcon = 0 Then GoTo No_Icon
lngError = DrawIcon(Picture_hDC, 0, 0, lngIcon) 'Draw the icon in the box
'If that was unsucessful then we can't do anything about it
now!
lngError = DestroyIcon(lngIcon)
'Again we can't correct any errors now
Exit
Sub
Comments