-
Jul 7th, 2000, 08:52 AM
#1
Does anybody know how to extract the icons used for the standard objects like My computer, network drive, disconnected network drive, Hard Disk, floppy, CD etc. and add them to an imagelist?
I managed to extract the icons associated to a file, and display it in a picturebox, but I would also like to add them to an imagelist (in all sizes available 16*16, 32*32 etc)
Any help is appreciated.
Frans
-
Jul 7th, 2000, 09:12 AM
#2
-
Jul 7th, 2000, 09:27 AM
#3
I don't want to create .ico files. I want to extract them in code, so the icons used are always the same as used on that computer. I know some of these are stored in Shell32.dll, but how do I know (from code) which icon index is which icon. Also I noticed the My Computer icon on my desktop is not the same as the my computer icon in shell32.dll. I need to find out which icon is actually used on the user's computer (the file name and the icon index).
-
Jul 7th, 2000, 10:36 AM
#4
Addicted Member
Here's some constants where the registry seems to store the location of icons (some programs such as microangelo can change these icons so by checking with the registry you can ensure you're extracting the desired icon)
Public Const REG_SHELL_ICONS = "SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Icons"
Public Const REG_MYCOMPUTER_ICON = "CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\DefaultIcon"
Public Const REG_CONTROLPANEL_ICON = "CLSID\{21EC2020-3AEA-1069-A2DD-08002B30309D}\DefaultIcon"
Public Const REG_PRINTERS_ICON = "CLSID\{2227A280-3AEA-1069-A2DE-08002B30309D}\DefaultIcon"
Public Const REG_DIALUPNETWORKING_ICON = "CLSID\{992CFFA0-F557-101A-88EC-00DD010CCC48}\DefaultIcon"
Public Const REG_RECYCLE_ICON = "CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\DefaultIcon"
What I've been fooling around with is first by checking in REG_SHELL_ICONS for any overriding icons. For example, lets say in my system I made my own icon for folders (which I have). in the REG_SHELL_ICONS section of the registry there will be a new key labeled with the value of the icon it's replacing's index. For example, closed folders icon is shell32.dll, 3 and open folder is shell32.dll,4 ... therefore in REG_SHELL_ICONS there with be 2 new values like follows:
3="C:\My Files\MyClosedFolder.ico"
4="C:\My Files\MyOpenFolder.ico"
So by using api calls you can check these first, and if they don't exist then you simple extract the icons from shell32.dll.
I'm sorry I can't be more specific and don't have any examples just yet, the code I have is still very disorganized and has some bugs.
Here's the api's you may want to look into though...
'API Declarations: Icons
Public 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
Public Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long
Public 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
Public Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" (ByVal pszPath As Any, ByVal dwFileAttributes As Long, psfi As SHFILEINFO, ByVal cbFileInfo As Long, ByVal uFlags As Long) As Long
'API Declarations: System Information
Public Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
'API Declarations: Registry
Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
'Constants used with API's (*Note)
Public Const MAX_PATH = 260
Public Const DI_NORMAL = &H3
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const KEY_WRITE = &H20006
Public Const REG_SZ = 1
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H0
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const SHGFI_ATTRIBUTES = &H800
Public Const SHGFI_DISPLAYNAME = &H200
Public Const SHGFI_EXETYPE = &H2000
Public Const SHGFI_ICON = &H100
Public Const SHGFI_ICONLOCATION = &H1000
Public Const SHGFI_LARGEICON = &H0
Public Const SHGFI_LINKOVERLAY = &H8000
Public Const SHGFI_OPENICON = &H2
Public Const SHGFI_PIDL = &H8
Public Const SHGFI_SELECTED = &H10000
Public Const SHGFI_SHELLICONSIZE = &H4
Public Const SHGFI_SMALLICON = &H1
Public Const SHGFI_SYSICONINDEX = &H4000
Public Const SHGFI_TYPENAME = &H400
Public Const SHGFI_USEFILEATTRIBUTES = &H10
' *Note: These are not all constants available for assosiated API's, just the ones
' that are used by this and coresponding modules.
Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Boolean
End Type
Public Type SHFILEINFO
hIcon As Long ' Icon Handle
iIcon As Long ' Econ index
dwAttributes As Long ' Flags
szDisplayName As String * MAX_PATH ' Path
szTypeName As String * 80 ' File Type
End Type
Remember to DestroyIcon() after extracting it to free up resources. What I did was extract icons, draw them into a picturebox with the picturebox's backcolor=treeview.backcolor and then add the picture to a listbox who'd maskcolor = that backcolor.
Good luck
-
Jul 7th, 2000, 12:44 PM
#5
That's what I was afraid of. It turns out to be some serious registry hacking. The keys you supplied are the keys for the default icons. The actually used icons are in HKEY_CURRENT_USER and in different locations for NT4 and Win 2000. So I have to check all windows versions for the registry key, or accept to display the default icons.
I was hoping for some api function to call for the associated file and icon index.
Thanks for the information.
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
|