-
1 Attachment(s)
Extract File Icon in XP
I've been using the attached code in Windows 2000 to get a files icon, and it works fine.
But when I run it in Windows XP and the file has a 256 colour icon, I get a black border round the outside of the icon (See ScreenShot.bmp in the attached Zip file).
How can I get a 256 colour file icon in Windows XP without the black border?
Thanks in advance
:)
-
Can't reply to your PM m8, but am looking at it.....
Why can't we reply to PM's - this **** is all fecked up!
-
I don't know what's happened to the User CP.
Private messages are fecked and I can't see any threads when I click View All Subscribed Threads.
Something has gone a bit pair shaped.
Cheers for looking into it Crispin
-
Flippin eck, VBF may die b4 I hit 1000 posts, I may have to start posting drivel in the code forums......oh wait - I do that already :D
-
1 Attachment(s)
Your attachment didn't work for me in Windows 2000. Clicking the button didn't do anything
Anyway, I slapped this together with some prefab code, see what happens
-
For chrisjk - you need to change the pathname he's using to find kernel32.dll - i.e. substitute WINNT for Windows..
For VB6Coder ...
Your code looks fine to me - the only difference I see compared to your screenshot is that the right-hand vertical edge has a slightly thicker black area.
Some experiments...
try using largeicons and see if similar differences occur
also use other icons (use various EXE paths instead of the kernel32.dll one) and see what happens
Might the problem be related to METRICS settings differences twixt your XP and 2000 systems? Check that the icon size settings match.... the 16x16 and 32x32 sizes can actually be varied (I think?) ... sorry, clutching at straws, really!!
Hope this helps.... without XP access I can't do much....
Dr Memory :cool:
-
windows xp has the ability to add shadows to icons. that's what the black thing is. the icon you are getting is the Windows XP version, not the 256 color version.
-
There you go, it's not a bug, it's a feature!!!!!!
-
Copy the following code into the declarations section of a module.
Private Type PicBmp
Size As Long
tType As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare Function OleCreatePictureIndirect _
Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _
ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function ExtractIconEx Lib "shell32.dll" _
Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal _
nIconIndex As Long, phiconLarge As Long, phiconSmall As _
Long, ByVal nIcons As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal _
hicon As Long) As Long
Function
Public Function GetIconFromFile(FileName As String, _
IconIndex As Long, UseLargeIcon As Boolean) As Picture
'Parameters:
'FileName - File (EXE or DLL) containing icons
'IconIndex - Index of icon to extract, starting with 0
'UseLargeIcon-True for a large icon, False for a small icon
'Returns: Picture object, containing icon
Dim hlargeicon As Long
Dim hsmallicon As Long
Dim selhandle As Long
'IPicture requires a reference to "Standard OLE Types."
Dim pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
If ExtractIconEx(FileName, IconIndex, hlargeicon, _
hsmallicon, 1) > 0 Then
If UseLargeIcon Then
selhandle = hlargeicon
Else
selhandle = hsmallicon
End If
'Fill in with IDispatch Interface ID.
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
'Fill Pic with necessary parts.
With pic
.Size = Len(pic) 'Length of structure.
.tType = vbPicTypeIcon 'Type of Picture (bitmap).
.hBmp = selhandle 'Handle to bitmap.
End With
'Create Picture object.
Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic)
'Return the new Picture object.
Set GetIconFromFile = IPic
DestroyIcon hsmallicon
DestroyIcon hlargeicon
End If
End Function
Example
Set Picture1.Picture = GetIconFromFile("c:windowsmoricons.dll", _
0, True)
This will paint the MS-DOS icon onto Picture1 in the normal sized icon(ie. 32x32). You can then use the PaintPicture function to rearrange and resize it.
Note: You must select Standard OLE Types in the Project|References box