







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
This lecture handout is for Windows Programming course. It was provided by Prof. Jaimini Chinmay at Ambedkar University, Delhi. It includes: Type, window, Resources, Controls, Statments, Description, Cursor, Menu, Accelerator
Typology: Study notes
1 / 13
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.)
Defines a template that an application can use to create dialog boxes.
DIALOGEX Defines a template that an application can use to create dialog boxes.
FONT Specifies the name of a file that contains a font.
Defines an icon or animated icon by naming it and specifying the name of the file that contains it. (To use a particular icon, the application requests it by name.)
MENU Defines the appearance and function of a menu.
MENUEX Defines the appearance and function of a menu.
Defines a message table by naming it and specifying the name of the file that contains it. The file is a binary resource file generated by the message compiler.
POPUP Defines a menu item that can contain menu items and submenus.
RCDATA Defines data resources. Data resources let you include binary data in the executable file.
STRINGTABLE Defines string resources. String resources are Unicode or ASCII strings that can be loaded from the executable file.
User-Defined Defines a resource that contains application-specific data.
VERSIONINFO Defines a version-information resource. Contains information such as the version number, intended operating system, and so on.
Control Description
AUTO3STATE Creates an automatic three-state check box control.
AUTOCHECKBOX Creates an automatic check box control.
AUTORADIOBUTTON Creates an automatic radio button control.
CHECKBOX Creates a check box control.
COMBOBOX Creates a combo box control.
CONTROL Creates an application-defined control.
CTEXT Creates a centered-text control.
DEFPUSHBUTTON Creates a default pushbutton control.
EDITTEXT Creates an edit control.
GROUPBOX Creates a group box control.
ICON Creates an icon control. This control is an icon displayed in a dialog box.
LISTBOX Creates a list box control.
LTEXT Creates a left-aligned text control.
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 script-file parameter specifies the name of the resource-definition file that contains the names, types, filenames, and descriptions of the resources to be compiled. The options parameter can be one or more of the following command-line options.
Options
/? Displays a list of RC command-line options. /d Defines a symbol for the preprocessor that you can test with the #ifdef directive. /fo resname Uses resname for the name of the .RES file. /h Displays a list of RC command-line options. /i Searches the specified directory before searching the directories specified by the INCLUDE environment variable. /l codepage Specifies default language for compilation. For example, -l409 is equivalent to including the following statement at the top of the resource script file: LANGUAGE LANG_ENGLISH,SUBLANG_ENGLISH_US
For more information, see Language Identifiers.
Alternatively, you use #pragma code_page(409) in the .RC file.
/n Null terminates all strings in the string table.
/r Ignored. Provided for compatibility with existing makefiles.
/u Undefines a symbol for the preprocessor.
/v Displays messages that report on the progress of the compiler.
/x Prevents RC from checking the INCLUDE environment variable when searching for header files or resource files.
Options are not case sensitive and a hyphen ( - ) can be used in place of a slash mark ( / ). You can combine single-letter options if they do not require any additional parameters. For example, the following two commands are equivalent:
rc /V /X SAMPLE.RC rc -vx sample.rc
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.
Return Value: If the function succeeds, the return value is the number of TCHAR s copied into the buffer, not including the null-terminating character, or zero if the string resource does not exist. To get extended error information, call GetLastError.
A keyboard accelerator , also known as a shortcut key, is a keystroke or combination of keystrokes that generates a WM_COMMAND message. Keyboard accelerators are often used as shortcuts for commonly used menu commands, but you can also use them to generate commands that have no equivalent menu items. Include keyboard accelerators for any common or frequent actions, and provide support for the common shortcut keys where they apply.
You can use an ASCII character code or a virtual-key code to define the accelerator. A virtual key is a device-independent value that identifies the purpose of a keystroke as interpreted by the Windows keyboard device driver. An ASCII character code makes the accelerator case-sensitive. The ASCII "C" character can define the accelerator as ALT+c rather than ALT+C. Because accelerators do not need to be case-sensitive, most applications use virtual-key codes for accelerators rather than ASCII character codes.
To create an accelerator table
An accelerator table consists of an array of ACCEL data structures, each of which defines an individual accelerator.
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:
If the specified window is the active window and no window has the keyboard focus (which is generally the case if the window is minimized), TranslateAccelerator translates WM_SYSKEYUP and WM_SYSKEYDOWN messages instead of WM_KEYUP and WM_KEYDOWN messages.
If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, TranslateAccelerator does not send a WM_COMMAND message. However, if an accelerator keystroke occurs that does not match any of the items in the window’s menu or in the window menu, the function sends a WM_COMMAND message, even if the window is minimized.
Figure 2
Alt + Backspace is pressed
WM_COMMAND message With wParam=low-word: ID_DO_BACK
Translate Accelerator sends a WM_COMMAND message.
Practise to design your own resource including menus, bitmaps, dialogs, etc in Visual Studio Resource Developer.