Visiters Welcomed

Wednesday, November 20, 2013

Creating and changing the .exe Icon


Like all things done on the computer there are multiple ways to accomplish a task.

You can use various software freely available from the net to accomplish the creation and loading of icon images.
I have listed a few options below so lets get started:

Software Option #1
- XN Resource Editor
- - Not largely documented but seems to be widely used by other users on the net including many forums.
- - Created by Colin Wilson

Software Option #2
- Resource Hacker
- - An older program than the formerly stated but is thus more widely documented.

Software Option #3
- IcoFx v.1.6.4
- - v.1.6.4 is free but if you download any of their newer versions it's only free for 30 days.

 Software Option #4
You can also create icon files using Adobe Photoshop by downloading the .ico save file type. If I am just replacing one specific file like the chili framework uses I will use Photoshop. 

If you wish to not download any of the software options one can also use the online upload ICO converter - IcoConverter

My favorite software of the bunch is IcoFx. Developed as an icon editor it is by far the most polished compared to the other two above. There is a resource editor built into this software as well.

So without any further ado I am going to walk you through the process of how I create, alter, and save icon files to be held in the resource file.

1. I start out by saving the original resource file found in the Assets folder. It's the file that ends with ( .res ). I save the original in a new folder in Assets called "OriginalResourceFile". You can name it whatever you like. This serves as a backup in case something fouls up during the changes we are going to make.

2. Renaming the resource file:
It can be renamed from inside Visual Studio by right clicking the file name in the solution explorer and choosing rename or double left clicking on the name will accomplish the same.

3. Saving multiple image sizes in one icon file using IcoFx:

- File -> Import Image: navigate to your image file you wish to replace chili's image with.
- - CLICK "Open".

- - Then CLICK on the windows symbol in the tool bar, a popup window will appear for you to choose the sizes of images saved inside the icon file.
- - Choose the sizes you wish and CLICK "OK".

- - File -> Save As: navigate to where you wish to save your file, name the file and CLICK "Save".

4. Now that we have our file to upload open Resource Hacker or like software.
- File -> Open: Navigate to the resource file we renamed earlier and select "Open".
- If the file is not showing up make sure under Files Of Type: Resource(.res) is selected.
- On the left there is a tree of folders. Two root files named Icon and Icon Group.
- Clicking the "+" symbol next to the Icon Group folder. You should now see two sub folders name 101 and 103. 101 holds the 16x16 icon and 103 holds the 32x32 icon.
- Click the "+" next to each folder to see these files.
- Select the "0" next to the gear symbol in the 101 folder.
- Select "Action" -> replace Icon: CLICK "Open File With New Icon..." Navigate to the .ico file we created in the earlier steps.
- CLICK "Replace"

Follow the same procedure for the 103 file.

Congratulations! Back on Visual Studio Re-Compile your program ( Ctrl+F5 ) and you're done!

Advanced:

Sometimes having a taskbar icon of 32x32 on larger monitors looks a little pixelated. So for those of you that are still with me we are going to add 48x48 size support to the chili framework.

1. We need to create a 48x48 version of our icon and I'm going to assume since you got this far you can figure that out as described above.

2. Lets add some code. Open VS ( Visual Studio ) Resource.h:

#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif

#define IDI_APPICON16 101 // 16x16
#define IDI_APPICON32 103 // 32x32
// Add the following
#define IDI_APPICON48 105 // 48x48

3. Now lets change some code. Windows.cpp:

int WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
   WNDCLASSEX wc = { sizeof( WNDCLASSEX ),
                                           CS_CLASSDC, MsgProc,
                                           0,
                                           0,
                                           GetModuleHandle( NULL ),
                                           NULL,
                                           NULL,
                                           NULL,
                                           NULL,
                                           L"Chili DirectX Framework Window",
                                           NULL
                                        };
    wc.hIconSm = (HICON)LoadImage( hInst,
                                                                MAKEINTRESOURCE( IDI_APPICON16 ),
                                                                IMAGE_ICON,
                                                                16,
                                                                16,
                                                                0
                                                             );
// Commented the next line out
   //wc.hIcon   = (HICON)LoadImage( hInst,
                                                              MAKEINTRESOURCE( IDI_APPICON32 ),
                                                              IMAGE_ICON,
                                                              32,
                                                              32,
                                                              0
                                                            );
// Replacing it with the next line
   wc.hIcon   = (HICON)LoadImage( hInst,
                                                            MAKEINTRESOURCE( IDI_APPICON48 ),
                                                            IMAGE_ICON,
                                                            48,
                                                            48,
                                                            0
                                                          );

No comments:

Post a Comment