Home | Email 

Windows Programming Pages
 

Prev | Up | Next

Lesson 4 - Resources, Dialogs and Internationalization issues

Click here to download the source files to this tutorial.

In this lesson, we'll take a look at Windows Resources. You'll learn to specify your application icon, keyboard accelerators and string tables. You'll also learn to include a very important kind of resource - the Dialog resource. After that we'll take a look at internationalization issues and how you can write applications that can be easily ported to other languages.

An introduction to resources

.res files

compiling them

Adding an application icon

When Windows Explorer has to draw an icon for an .exe file, it looks for the first icon in the executable resource. What this means is, you must number the application icon with the lowest number so that it is found first.

Lets call our application icon IDI_APP_ICON. We give it the lowest possible number 1. Add the following code in the respective files:

/* resource.rc
**/

...

IDI_APP_ICON ICON DISCARDABLE "main.ico"
/* resource.h
**/

#define IDI_APP_ICON 1

main.ico gives the path of the icon (If you've downloaded the zip file you'll see that I've used Sherman the shark as the main icon).

If you compile the application and then point Windows Explorer to the directory where your executable file is located, you'll see your application icon is the one you've specified.

This done, we have to tell windows to draw the icon on the upper left corner of the window. This is easily done. All you have to do is specify the class icon as IDI_APP_ICON.

/* interface.c */
    ...
    wcx.cbWndExtra = 0; 
    wcx.hInstance = hInstance; // Instance of the application
    wcx.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); // Class Icon
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW); // Class Cursor
    ...

What happens if the top level windows' class icon isn't the lowest numbered icon? Try it. You'll see something odd. Explorer displays one icon and the top left corner of your application displays another icon.

Adding a Dialog Window

 

 

<Last line placeholder>

Last Updated: May 14, 2004 • This page and its contents are copyright © 2002-2004 Pravin Paratey • Copyright NoticeDisclaimer
1