Solution for obtaining Windows system icons

Source: Internet
Author: User

If you want to obtain system icons such as my computer or network neighbor in Windows, you can find the following solutions.

Solution 1
Use icons to extract software from C:/winnt/system32/shell32.dll or C: extracted from/winnt/assumer.exe and added it to your program (the path varies with the operating system and installation directory) the disadvantage of this method is that the system icons of different operating systems have some changes. For example, the system icons of 2003 and 2000 have great changes. If you extract the 2000 icon, if the application runs in 2003, it may seem awkward.

Solution 2
The C:/winnt/system32/shell32 file is also used for extraction, but this time the registry and Windows functions are used for extraction. The Code is as follows:
Hicon ctestdlg: getshellicon (INT nindex)
{
Hicon = NULL;
Hkey hkeyshellicons;

// Open the registry and read the corresponding icon Project
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;
}
This method overcomes the disadvantages of inflexible use of the first method, but the amount of code is large. (The index directory is listed at the end)

Solution 3
Use the Shell functions shgetspecialfolderlocation and shgetfileinfo. The Code is as follows:

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 );
In this case, the icon and hicon in shinfo Save the resulting icon values.
This method has both flexibility and a small amount of code, and is recommended. The second parameter in shgetspecialfolderlocation is the csidl value of the desired image.

[Appendix 1: nindex value description]
Meaning of nindex
0 default icon
1 default. Doc icon *
2. executable file icon
3. Close the folder icon
4. Open the folder icon
5 5.25 'Drive icons
6 3.5 'Drive icons
7. removable drive icons
8 hard drive icon
9 network drive icon
10 disconnected network drive icon
11 CD-ROM drive icons
12 RAM drive icon
13 Network icons
14 network connection icon u
15 network workstation icons
16 local printer icons *
17 Network icon u
18 network workgroup icon u
19 program group icon s
20 document icon s
21. Set the icon S.
22. Search icon s
23. Help icon s
24 run icon s
25 sleep icon s
26 docking station icon u
27 shutdown icon s
28 share icon t
29 shortcut arrow icon t
30 arrows icon u
31 empty recycle bin icon *
32 full recycle bin icon *
33. Dial-Up Network icon *
34 desktop icons
35 console icons *
36 Program Group icons s
37 printer folder icon *
38 font folder icon *
39 windows flag icons *
40 audio CD icon
.
.
.
. 49

The instructions marked with symbols have special usage:
* These icons can be set elsewhere in the registry.
T these icons must be blank backgrounds.
S will be used in the Start Menu.
U These icons may not be used or cannot be modified through the Registry

[Appendix 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 locations, 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 shocould 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 tables les 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 adminiining 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_comment topdirectory
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 ENTs. 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_topics topdirectory
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 ents 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 ents 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 ents 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 shoshould 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 messaging SS 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 ents and settings/ Username/Recent. to create a shortcut in this folder, use shaddtorecentdocs. in addition to creating the Starting Cut, this function updates the shell's list of recent sort ents and adds the sort cut to the sort ents 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 ents 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.