July 20, 2018
Hot Topics:

Going Mobile: How to Port Your Win32 Code to Windows CE

  • October 17, 2002
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

The Resource File Is A Road Map

If a Windows application has a user interface at all, most of it's significant details are recorded in the resource file. Figure 1 is a screenshot of a simple Win32 application that includes icon, accelerator, dialog, menu, and string table resources.

Let's dissect the resource file for this application and assess the relative portability of its user interface.

Figure 1 - A simple Win32 application.


//Microsoft Developer Studio generated resource script.//#include "resource.h"#define APSTUDIO_READONLY_SYMBOLS/////////////////////////////////////////////////////////////////////// Generated from the TEXTINCLUDE 2 resource.//#define APSTUDIO_HIDDEN_SYMBOLS#include "windows.h"#undef APSTUDIO_HIDDEN_SYMBOLS#include "resource.h"///////////////////////////////////////////////////////////////////#undef APSTUDIO_READONLY_SYMBOLS///////////////////////////////////////////////////////////////////// English (U.S.) resources#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)#ifdef _WIN32LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US#pragma code_page(1252)#endif //_WIN32//////////////////////////////////////////////////////////////////////// Icon//// Icon with lowest ID value placed first to ensure application// icon remains consistent on all systems.IDI_RESOURCE_FILE       ICON    DISCARDABLE     "resource_file.ICO"IDI_SMALL               ICON    DISCARDABLE     "SMALL.ICO"/////////////////////////////////////////////////////////////////////// Menu//IDC_RESOURCE_FILE MENU DISCARDABLE BEGIN    POPUP "&File"    BEGIN        MENUITEM "Open",                        ID_FILE_OPEN        MENUITEM "Close",                       ID_FILE_CLOSE        MENUITEM "Save",                        ID_FILE_SAVE        MENUITEM "SaveAs",                      ID_FILE_SAVEAS        MENUITEM "Print",                       ID_FILE_PRINT        MENUITEM "Print Setup",                 ID_FILE_PRINTSETUP        MENUITEM SEPARATOR        MENUITEM "E&xit",                       IDM_EXIT        MENUITEM SEPARATOR        MENUITEM "Recent Files",                ID_FILE_RECENTFILES    END    POPUP "More Menus"    BEGIN        POPUP "Submenu 1"        BEGIN            MENUITEM "Item1",                   ID_SUBMENU1_ITEM1            MENUITEM "Item2",                   ID_SUBMENU1_ITEM2        END    END    POPUP "&Help"    BEGIN        MENUITEM "&About ...",                  IDM_ABOUT    ENDEND/////////////////////////////////////////////////////////////////////// Accelerator//IDC_RESOURCE_FILE ACCELERATORS MOVEABLE PURE BEGIN    "?",            IDM_ABOUT,              ASCII,  ALTEND/////////////////////////////////////////////////////////////////////// Dialog//IDD_ABOUTBOX DIALOG DISCARDABLE  22, 17, 230, 75STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENUCAPTION "About"FONT 8, "System"BEGIN    ICON            IDI_RESOURCE_FILE,IDC_MYICON,14,9,16,16    LTEXT           "resource_file Version 1.0",IDC_STATIC,49,10,                    119,8,SS_NOPREFIX    LTEXT           "Copyright (C) 2001",IDC_STATIC,49,20,119,8    DEFPUSHBUTTON   "OK",IDOK,195,6,30,11,WS_GROUPENDIDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 242, 201STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENUCAPTION "ResourceFile Example"FONT 8, "MS Sans Serif"BEGIN    DEFPUSHBUTTON   "OK",IDOK,185,5,50,14    PUSHBUTTON      "Cancel",IDCANCEL,185,25,50,14    EDITTEXT        IDC_EDIT1,25,25,135,45,ES_AUTOHSCROLL    LISTBOX         IDC_LIST1,25,95,95,50,LBS_SORT |                     LBS_NOINTEGRALHEIGHT |                     WS_VSCROLL | WS_TABSTOP    GROUPBOX        "Radio Button Group",IDC_STATIC,150,90,75,55    LTEXT           "Scrolling Listbox",IDC_STATIC,25,80,100,10    LTEXT           "Edit Control",IDC_STATIC,25,10,125,10END#ifdef APSTUDIO_INVOKED/////////////////////////////////////////////////////////////////////// TEXTINCLUDE//2 TEXTINCLUDE DISCARDABLE BEGIN    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"    "#include ""windows.h""\r\n"    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"    "#include ""resource.h""\r\n"    "\0"END3 TEXTINCLUDE DISCARDABLE BEGIN    "\r\n"    "\0"END1 TEXTINCLUDE DISCARDABLE BEGIN    "resource.h\0"END#endif    // APSTUDIO_INVOKED/////////////////////////////////////////////////////////////////////// DESIGNINFO//#ifdef APSTUDIO_INVOKEDGUIDELINES DESIGNINFO DISCARDABLE BEGIN    IDD_DIALOG1, DIALOG    BEGIN        LEFTMARGIN, 7        RIGHTMARGIN, 235        TOPMARGIN, 7        BOTTOMMARGIN, 194    ENDEND#endif    // APSTUDIO_INVOKED/////////////////////////////////////////////////////////////////////// String Table//STRINGTABLE DISCARDABLE BEGIN    IDS_APP_TITLE           "resource_file"    IDS_HELLO               "Hello World!"    IDC_RESOURCE_FILE       "RESOURCE_FILE"END#endif    // English (U.S.) resources///////////////////////////////////////////////////////////////////#ifndef APSTUDIO_INVOKED/////////////////////////////////////////////////////////////////////// Generated from the TEXTINCLUDE 3 resource./////////////////////////////////////////////////////////////////////#endif    // not APSTUDIO_INVOKED

Porting Icons and Cursors


Here's the fragment of the resource file that describes the application's icons:

// Icon with lowest ID value placed first to ensure application// icon remains consistent on all systems.IDI_RESOURCE_FILE       ICON    DISCARDABLE     "resource_file.ICO"IDI_SMALL               ICON    DISCARDABLE     "SMALL.ICO"

The first icon shown, IDI_RESOURCE_FILE, is the application's main icon. That is, it is the one that is displayed when the user creates a shortcut to the application. Win 32 applications' main icons are 32 by 32 pixels and may use the full range of system colors. By contrast, Windows CE icons must be no larger than 16 by 16 pixels, and must be explicitly loaded by the application. If the icon is too large, it won't load. The second icon in the resource file, IDI_SMALL, is used to represent the application in list views ( Windows Explorer, for example). This icon is superfluous on the CE side and should be eliminated.

Page 2 of 4

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date