得到windows系統表徵圖的解決方案

來源:互聯網
上載者:User

如果想得到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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.