得到windows系统图标的解决方案

来源:互联网 发布:windows版本发布年代 编辑:程序博客网 时间:2024/06/05 19:53

得到windows系统图标的解决方案
阅读:579次   时间:2004-12-09 00:00:00   字体:[大 中 小]
如果想得到windows中我的电脑或者网络邻居等系统图标可以有如下解决办法。

方案一
        用图标提取软件从c:\winnt\system32\SHELL32.dll或者C:\WINNT\Explorer.exe中提取出来然后加入到自己的程序中(路径随操作系统和安装目录不同而变化)这种方法的缺点是不同的操作系统的系统图标有一些变化,比如说2003和2000的系统图标就有很大变化,如果你提取的是2000的图标,应用程序如果在2003下运行可能看起来有一些别扭。

方案二
        同样是利用c:\winnt\system32\SHELL32文件来提取,但是这次是利用注册表和windows的函数来完成。代码如下:
HICON CTestDlg::GetShellIcon(int nIndex)
{
        HICON hIcon=NULL;
        HKEY hkeyShellIcons;

        //打开注册表源码天空,读相应的图标项目
        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell I                                        cons", 0,KEY_READ,&hkeyShellIcons)==ERROR_SUCCESS)
        {
              char szBuffer[MAX_PATH];
              DWORD dwSize=MAX_PATH;
    
              char szIndex[4];
              sprintf(szIndex,"%d",nIndex);
              if(RegQueryValueEx(hkeyShellIcons,szIndex,NULL,NULL,(LPBYTE)szBuffer,&dwSize)==ERROR_SUCCESS)
              {
                   CString strFile,strIndex;
                   AfxExtractSubString(strFile,szBuffer,0,',');
                   AfxExtractSubString(strIndex,szBuffer,1,',');
                   ExtractIconEx(strFile,atoi(strIndex),NULL,&hIcon,1);
              }
              RegCloseKey(hkeyShellIcons);
        }
         if(!hIcon)
               ExtractIconEx("SHELL32.DLL",nIndex,NULL,&hIcon,1);
    
        return hIcon;
}
这种方法克服了第一种方法使用不灵活的缺点但是代码量比较大。(index目录在最后列出)

方案三
        利用shell函数SHGetSpecialFolderLocation和SHGetFileInfo。代码如下:

 LPITEMIDLIST lpItemIDList;
 SHFILEINFO shinfo;
 SHGetSpecialFolderLocation (this->m_hWnd, CSIDL_NETWORK, &lpItemIDList);
 SHGetFileInfo( (LPCTSTR)lpItemIDList,
                          NULL,
                          &shinfo,
                          sizeof(shinfo),
                          SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON| SHGFI_SMALLICON|SHGFI_PIDL);
这是shinfo中的icon和hicon保存了得到的icon的值。
这种方法既有灵活性,代码量也比较少,推荐使用。在SHGetSpecialFolderLocation中的第二个参数是想得到的图片的CSIDL值。

 


【附表1:nindex值说明】
nIndex  意义                                       说明
0          默认图标
1          默认的 .doc 图标*
2          可执行文件图标
3          关闭的文件夹图标
4          打开的文件夹图标
5          5.25' 驱动器图标
6          3.5' 驱动器图标
7          可移动的驱动器图标
8          硬盘驱动器图标
9          网络驱动器图标
10        断开的网络驱动器图标
11        CD-ROM驱动器图标
12        RAM驱动器图标
13        整个网络图标
14        网络连接图标 u
15        网络工作站图标
16        本地打印机图标 *
17        网络图标 u
18        网络工作组图标 u
19        程序组图标 s
20        文档图标 s
21        设置图标 s
22        查找图标  s
23        帮助图标  s
24        运行图标  s
25        睡眠图标  s
26        Docking Station 图标 u
27        关机图标 s
28        共享图标 t
29        快捷方式的箭头图标 t
30        大箭头图标 u
31        空回收站图标 *
32        满的回收站图标 *
33        拨号网络图标 *
34        桌面图标
35        控制台图标  *
36        程序组图标  s
37        打印机文件夹图标 *
38        字体文件夹图标 *
39        Windows旗帜图标 *
40        Audio CD 图标    
.
.
.
.49

后面标有符号的说明有特殊用法:
* 这些图标可以在注册表的其他地方的设置。
t 这些图标必须是空白背景。
s 这些图标将用在开始菜单上。
u 这些图标可能并没有使用或不能通过注册表修改

【附表2:CSIDL Values】


A number of folders are used frequently by applications, but may not have the same name or location on any given system. For example, the system folder may be "C:\Windows" on one system and "C:\Winnt" on another. CSIDL values provide a unique system-independent way to identify these special folders. The values supersede the use of environment variables for this purpose.

A CSIDL is used in conjunction with one of four Shell functions, SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation, and SHGetSpecialFolderPath, to retrieve a special folder's pathname or item ID list (PIDL).

If a special folder does not exist, you can force its creation by using the following special CSIDL:

CSIDL_FLAG_CREATE
Version 5.0. Combine this CSIDL with any of the CSIDLs listed below to force the creation of the associated folder.
The remaining CSIDLs correspond to either file system folders or virtual folders. Where the CSIDL identifies a file system folder, a commonly used path is given as an example. Other paths may be used. Some CSIDLs can be mapped to an equivalent %VariableName% environment variable. CSIDLs are more reliable, however, and should be used if possible.

CSIDL_ADMINTOOLS
Version 5.0. File system directory that is used to store administrative tools for an individual user. The Microsoft Management Console will save customized consoles to this directory, and it will roam with the user.
CSIDL_ALTSTARTUP
File system directory that corresponds to the user's nonlocalized Startup program group.
CSIDL_APPDATA
Version 4.71. File system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable ShFolder.dll for systems that do not have the Internet Explorer 4.0 integrated Shell installed.
CSIDL_BITBUCKET
Virtual folder containing the objects in the user's Recycle Bin.
CSIDL_COMMON_ADMINTOOLS
Version 5.0. File system directory containing containing administrative tools for all users of the computer.
CSIDL_COMMON_ALTSTARTUP
File system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Windows NT® systems.
CSIDL_COMMON_APPDATA
Version 5.0. Application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data.
CSIDL_COMMON_DESKTOPDIRECTORY
File system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT® systems.
CSIDL_COMMON_DOCUMENTS
File system directory that contains documents that are common to all users. Typical paths are C:\Documents and Settings\All Users\Documents. Valid for Windows NT® systems and Windows 95 and Windows 98 systems with Shfolder.dll installed.
CSIDL_COMMON_FAVORITES
File system directory that serves as a common repository for all users' favorite items. Valid only for Windows NT® systems.
CSIDL_COMMON_PROGRAMS
File system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT® systems.
CSIDL_COMMON_STARTMENU
File system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT® systems.
CSIDL_COMMON_STARTUP
File system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT® systems.
CSIDL_COMMON_TEMPLATES
File system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT® systems.
CSIDL_CONTROLS
Virtual folder containing icons for the Control Panel applications.
CSIDL_COOKIES
File system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies.
CSIDL_DESKTOP
Windows Desktop—virtual folder that is the root of the namespace.
CSIDL_DESKTOPDIRECTORY
File system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop
CSIDL_DRIVES
My Computer—virtual folder containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.
CSIDL_FAVORITES
File system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites.
CSIDL_FONTS
Virtual folder containing fonts. A typical path is C:\WINNT\Fonts.
CSIDL_HISTORY
File system directory that serves as a common repository for Internet history items.
CSIDL_INTERNET
Virtual folder representing the Internet.
CSIDL_INTERNET_CACHE
Version 4.72. File system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Temporary Internet Files.
CSIDL_LOCAL_APPDATA
Version 5.0. File system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data.
CSIDL_MYMUSIC
File system directory that serves as a common repository for music files. A typical path is C:\My Music.
CSIDL_MYPICTURES
Version 5.0. My Pictures folder. A typical path is C:\Documents and Settings\username\My Documents\My Pictures.
CSIDL_NETHOOD
A file system folder containing the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood.
CSIDL_NETWORK
Network Neighborhood—virtual folder representing the root of the network namespace hierarchy.
CSIDL_PERSONAL
File system directory that serves as a common repository for documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use the technique described in Managing the File System. CSIDL_PRINTERS
Virtual folder containing installed printers.
CSIDL_PRINTHOOD
File system directory that contains the link objects that may exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood.
CSIDL_PROFILE
Version 5.0. User's profile folder.
CSIDL_PROGRAM_FILES
Version 5.0. Program Files folder. A typical path is C:\Program Files.
CSIDL_PROGRAM_FILES_COMMON
Version 5.0. A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT® and Windows® 2000 systems.
CSIDL_PROGRAMS
File system directory that contains the user's program groups (which are also file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs.
CSIDL_RECENT
File system directory that contains the user's most recently used documents. A typical path is C:\Documents and Settings\username\Recent. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the Documents submenu of the Start menu.
CSIDL_SENDTO
File system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo.
CSIDL_STARTMENU
File system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu.
CSIDL_STARTUP
File system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT® or starts Windows® 95. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup.
CSIDL_SYSTEM
Version 5.0. System folder. A typical path is C:\WINNT\SYSTEM32.
CSIDL_TEMPLATES
File system directory that serves as a common repository for document templates.
CSIDL_WINDOWS
Version 5.0. Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\WINNT.


author:simahao 2005.1.3
详细请参考:http://www.codesky.net/article/200412/49497.html

0 0
原创粉丝点击