








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Types of windows resources, Resource Definition Statements, Resource Statements in Resource File, Using Resource Compiler, Loading an Icon from the resource table. As you can see in this file, how descriptive above mentioned points are explained in this lecture of computer programming. VU is one of best university for computer science in our country.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









application. A resource can be either standard or defined. The data in a standard resource describes an icon, cursor, menu, dialog box, bitmap, enhanced metafile, font, accelerator table, message-table entry, string-table entry, or version information. An application- defined resource, also called a custom resource, contains any data required by a specific application.
Following are the Windows Resources are used in windows.
The resource-definition statements define the resources that the resource compiler puts in the resource (.Res) file. After the .Res file is linked to the executable file, the application can load its resources at run time as needed. All resource statements associate an identifying name or number with a given resource.
The resource-definition statements can be divided into the following categories:
The following tables describe the resource-definition statements.
Resource Description
ACCELERATORS Defines menu accelerator keys.
Defines a bitmap by naming it and specifying the name of the file that contains it. (To use a particular bitmap, the application requests it by name.)
Defines a cursor or animated cursor by naming it and specifying the name of the file that contains it. (To use a particular cursor, the application requests it by name.)
PUSHBOX Creates a push box control.
PUSHBUTTON Creates a push button control.
RADIOBUTTON Creates a radio button control.
RTEXT Creates a right-aligned control.
SCROLLBAR Creates a scroll bar control.
STATE3 Creates a three-state check box control.
Statement Description
CAPTION Sets the title for a dialog box.
CHARACTERISTICS Specifies information about a resource that can be used by tool that can read or write resource-definition files.
CLASS Sets the class of the dialog box.
EXSTYLE Sets the extended window style of the dialog box.
FONT Sets the font with which the system will draw text for the dialog box.
Sets the language for all resources up to the next LANGUAGE statement or to the end of the file. When the LANGUAGE statement appears before the beginning of the body of an ACCELERATORS , DIALOG , MENU , RCDATA , or STRINGTABLE resource definition, the specified language applies only to that resource.
MENU Sets the menu for the dialog box.
MENUITEM Defines a menu item.
STYLE Sets the window style for the dialog box.
VERSION Specifies version information for a resource that can be used by tool that can read or write resource-definition files.
Figure 1
ICON resource statement in a resource file (.rc)
#define IDI_ICON 101
IDI_ICON ICON DISCARDABLE “vu.ico” Integer id reserved icon word filename 101 ICON DISCARDABLE “vu.ico”
To start RC, use the RC command.
RC [[options]] script-file
.rc File (text file containing resource statements
Link with other files to make final EXE (using linker) File in windows.
Compile to .res file (using resource compiler)
The LoadIcon function loads the specified icon resource from the executable (.exe) file associated with an application instance.
HICON LoadIcon(
HINSTANCE hInstance , /handle to the instance/ LPCTSTR lpIconName /string to the icon data/ );
hInstance: Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded.
lpIconName: Pointer to a null-terminated string that contains the name of the icon resource to be loaded. Alternatively, this parameter can contain the resource identifier in the low-order word and zero in the high-order word. Use the MAKEINTRESOURCE macro to create this value.
To use one of the predefined icons, set the hInstance parameter to NULL and the lpIconName parameter to one of the following values.
IDI_APPLICATION: Default application icon. IDI_ASTERISK: Same as IDI_INFORMATION. IDI_ERROR: Hand-shaped icon. IDI_EXCLAMATION: Same as IDI_WARNING. IDI_HAND: Same as IDI_ERROR. IDI_INFORMATION: Asterisk icon. IDI_QUESTION: Question mark icon. IDI_WARNING: Exclamation point icon. IDI_WINLOGO: Windows logo icon.
Return Value: If the function succeeds, the return value is a handle to the newly loaded icon. If the function fails, the return value is NULL. To get extended error information, use GetLastError.
LoadIcon loads the icon resource only if it has not been loaded; otherwise, it retrieves a handle to the existing resource. The function searches the icon resource for the icon most appropriate for the current display. The icon resource can be a color or monochrome bitmap.
LoadIcon can only load an icon whose size conforms to the SM_CXICON and SM_CYICON system metric values. Use the LoadImage function to load icons of other sizes.
#include “resource.h”
STRINGTABLE DISCARDABLE BEGIN IDS_STRING1 “This is Virtual University" IDS_STRING2 "MyWindowClass" IDS_STRING3 “My Novel Programme" END
The LoadString function loads a string resource from the executable file associated with a specified module, copies the string into a buffer, and appends a terminating null character.
int LoadString(
HINSTANCE hInstance ,//handle to application instance/ UINT uID , ///id of the string/ LPTSTR lpBuffer , /buffer to receive string data/ int _nBufferMax /maximum buffer size is available for the string data to store*/_ );
hInstance: Handle to an instance of the module whose executable file contains the string resource. To get the handle for the application itself, use GetModuleHandle(NULL).
uID: Specifies the integer identifier of the string to be loaded.
lpBuffer: Pointer to the buffer to receive the string.
nBufferMax: Specifies the size of the buffer, in TCHAR s. This refers to bytes for versions of the function or WCHAR s for Unicode versions. The string is truncated and null terminated if it is longer than the number of characters specified.
#define ID_DO_BACK 1001 #define ID_ACC2 1002 #define ID_DRAWSTRING 1003 ACCELERATOR ACCELERATORS DISCARDABLE BEGIN VK_BACK, ID_DO_BACK, VIRTKEY, ALT, NOINVERT VK_DELETE, ID_ACC2, VIRTKEY, ALT, NOINVERT … …… .. ...
. .... .. “^S", ID_DRAWSTRING, ASCII, NOINVERT END
Labelling: Virtual Key or ASCII ID Options(VIRTKEY, ASCII, ALT, CONTROL)
The LoadAccelerators function loads the specified accelerator table.
HACCEL LoadAccelerators(
HINSTANCE hInstance , ///handle to the application instance/ LPCTSTR lpTableName /string to the table name/ );
hInstance: Handle to the module whose executable file contains the accelerator table to load. lpTableName: Pointer to a null-terminated string that contains the name of the accelerator table to load. Alternatively, this parameter can specify the resource identifier of an accelerator-table resource in the low-order word and zero in the high-order word. To create this value, use the MAKEINTRESOURCE macro.
Return Value: If the function succeeds, the return value is a handle to the loaded accelerator table. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
The TranslateAccelerator function processes accelerator keys for menu commands. The function translates a WM_KEYDOWN or WM_SYSKEYDOWN message to a WM_COMMAND or WM_SYSCOMMAND message (if there is an entry for the key in the specified accelerator table) and then sends the WM_COMMAND or WM_SYSCOMMAND message directly to the appropriate window procedure. TranslateAccelerator does not return until the window procedure has processed the message.
int TranslateAccelerator(
HWND hWnd , /handle to the window to whom accelerator attached/ HACCEL hAccTable , /accelerate table/ LPMSG lpMsg /MSG structure/ );
hWnd: Handle to the window whose messages are to be translated.
hAccTable: Handle to the accelerator table. The accelerator table must have been loaded by a call to the LoadAccelerators function or created by a call to the CreateAcceleratorTable function.
lpMsg: Pointer to an MSG structure that contains message information retrieved from the calling thread's message queue using the GetMessage or PeekMessage function.
Return Value: If the function succeeds, the return value is nonzero.If the function fails, the return value is zero.
To differentiate the message that this function sends from messages sent by menus or controls, the high-order word of the wParam parameter of the WM_COMMAND or WM_SYSCOMMAND message contains the value 1.
Accelerator key combinations used to select items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator key combinations are translated into WM_COMMAND messages.
An accelerator need not correspond to a menu command.
If the accelerator command corresponds to a menu item, the application is sent WM_INITMENU and WM_INITMENUPOPUP messages, as if the user were trying to display the menu. However, these messages are not sent if any of the following conditions exist:
HACCEL hAccel;
//Load the accelerator table
hAccel = LoadAccelerator(hInstance, MAKEINTRESOURCE(ACCELERATOR))
While(GetMessage(&msg, .. .,... , ... )) {
//Call translateAccelerator to test if accelerator is pressed
If( !TranslateAccelerator(msg.hwnd, hAccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
case WM_COMMAND:
if(LOWORD(wParam) == ID_DO_BACK) { // accelerator is pressed }
In this lecture, we have been studying about resources. Resources are also very much important subject in Windows executable files. Resources are separately compiled using resource compiler. Resource compiler (RC) compiles them to binary resource and these binary resource are then become the part of final executable file. Resource files are simply text script files. Resource can be loaded from any DLL and EXE module. For loading the resource, we have useful resource functions like LoadString that loads a string from resource table and Load Icon etc. that loads an Icon data from resource data.
Practise to design your own resource including menus, bitmaps, dialogs, etc in Visual Studio Resource Developer.