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: \ winnt \ assumer.exe is extracted and then added 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 );
This is the value of the icon saved by the icon and hicon in shinfo.
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 * Software Development Network
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


 

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.