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 );