|
-
Jan 20th, 2000, 03:38 AM
#1
Thread Starter
Addicted Member
Ok, I have studied hard on icons ... and know a whole lot about them and the API now ... man that API's awesome.
Earlier you may recall I was having trouble extracting the 16x16 icon from files (that's the one you'd want to load into a listview control). Well, it's actually pretty simple, check it out...
Declarations...
Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As String, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal DIFlags As Long) As Long
Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
Const SHGFI_SMALLICON = &H1 ' get small icon
Const SHGFI_ICON = &H100 ' get icon
Const MAX_PATH = 260
Public Type SHFILEINFO
hIcon As Long ' out: icon
iIcon As Long ' out: icon index
dwAttributes As Long ' out: SFGAO_ flags
szDisplayName As String * MAX_PATH ' out: display name (or path)
szTypeName As String * 80 ' out: type name
End Type
Code ...
Dim icInfo As SHFILEINFO
Dim icHandle As Long
Dim x
Picture1.Cls
Picture1.BorderStyle = 0
Picture1.Appearance = 0
Picture1.AutoRedraw = True
Picture1.Width = ScaleX(16, vbPixels, vbTwips) 'Ensure correct size
Picture1.Height = ScaleY(16, vbPixels, vbTwips) 'Ensure correct size
'Get File's assosiated small icon
x = SHGetFileInfo(icPath, 0, icInfo, LenB(icInfo), SHGFI_ICON Or SHGFI_SMALLICON)
icIcon = iInfo.hIcon 'Set to small icon's handle
x = DrawIconEx(iBox.hdc, 0, 0, lIcon, iSize, iSize, 0, 0, DI_NORMAL)
Picture1.Picture = Picture1.Image
x = DestroyIcon(lcIcon)
That's just a simplified version ... no error handling or anything but I just figured it out. Let me know if you see anything that I may be doing wrong. Granted it's working but I don't know if it'll cause any unforseen probs.
------------------
Micah Carrick
http://micah.carrick.com
[email protected]
ICQ: 53480225
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|