How to extract and save ICON resources

Source: Internet
Author: User

 

What if you want to use beautiful icons in other applications? Some icon extraction tools may be used! So, do you know how they are implemented, and do not want to create a suitable icon Extraction Tool by yourself? It extracts ICON resources from various files and saves them as icons.(ICO), bitmap (BMP) two formats. After running the program, the interface is as follows:

 

 

Figure 1

In the above routine, I integrated an icon classCIcons corresponds to a bitmap class CDib, which contains four files: Icons. h, Icons. cpp, Dib. h, and Dib. cpp. After adding these four files to your project, you can use your own icon tool to call the classes.
Let's take a look at how to use them for implementation:
1. Extract and display the icon to the list box on the left.
The code is implemented as follows:
// Read the internal icons of various resources and display them in the list box on the left.

 

 

Void CIconSnapDlg: OnOK ()
   
{
   
CFileDialog fileDialog (TRUE ,"*. ICO ", NULL, NULL," resource file (*. ICO ,*. BMP ,*. EXE ,*. DLL ,*. ICL) | *. ICO ;*. BMP ;*. EXE ;*. DLL ;*. ICL | ");
   
If (fileDialog. DoModal () = IDOK)
   
{
   
SzOpenFileName = fileDialog. GetPathName ();
   
SzOpenFileExtName = fileDialog. GetFileExt ();
   
SzOpenFileExtName. MakeLower ();
   
 
   
M_List.ResetContent (); // you can clear the list box on the left.
   
 
   
// Read and display the ICON file
   
If (szOpenFileExtName = "ico ")
   
{
   
LpIR = pIcons-> ReadIconFromICOFile (szOpenFileName );
   
HICON hIcon;
   
HIcon = ExtractIcon (AfxGetInstanceHandle (), szOpenFileName, 0 );
   
If (hIcon! = NULL)
   
M_List.AddString (szOpenFileName );
   
Related Article

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.