






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
String and Menu Resource, Menu Handles, Menus, State of Menu Items, Menu Resource Definition Statement, Loading Menu, Specify default class Menu, Specify Menu in CreateWindow. 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 / 10
This page cannot be seen from the preview
Don't miss anything!







A menu is a list of items that specify options or groups of options (a submenu) for an application. Clicking a menu item opens a submenu or causes the application to carry out a command.
A menu is arranged in a hierarchy. At the top level of the hierarchy is the menu bar ; which contains a list of menus , which in turn can contain submenus. A menu bar is sometimes called a top-level menu , and the menus and submenus are also known as pop- up menus.
A menu item can either carry out a command or open a submenu. An item that carries out a command is called a command item or a command.
An item on the menu bar almost always opens a menu. Menu bars rarely contain command items. A menu opened from the menu bar drops down from the menu bar and is sometimes called a drop-down menu. When a drop-down menu is displayed, it is attached to the menu bar. A menu item on the menu bar that opens a drop-down menu is also called a menu name.
The menu names on a menu bar represent the main categories of commands that an application provides. Selecting a menu name from the menu bar typically opens a menu whose menu items correspond to the commands in a category. For example, a menu bar might contain a File menu name that, when clicked by the user, activates a menu with menu items such as New , Open , and Save. To get information about a menu bar, call GetMenuBarInfo.
Only an overlapped or pop-up window can contain a menu bar; a child window cannot contain one. If the window has a title bar, the system positions the menu bar just below it. A menu bar is always visible. A submenu is not visible, however, until the user selects a menu item that activates it. For more information about overlapped and pop-up windows, see Window Types.
Each menu must have an owner window. The system sends messages to a menu's owner window when the user selects the menu or chooses an item from the menu.
An application can use the GetSystemMenu function to create a copy of the default window menu to modify. Any window that does not use the GetSystemMenu function to make its own copy of the window menu receives the standard window menu.
The system generates a unique handle for each menu. A menu handle is a value of the HMENU type. An application must specify a menu handle in many of the menu functions. You receive a handle to a menu bar when you create the menu or load a menu resource.
To retrieve a handle to the menu bar for a menu that has been created or loaded, use the GetMenu function. To retrieve a handle to the submenu associated with a menu item, use the GetSubMenu or GetMenuItemInfo function. To retrieve a handle to a window menu, use the GetSystemMenu function.
Following are the states of Menu items:
POPUP "&Tools“ BEGIN MENUITEM "Write &Text", ID_TOOLS_WRITE_TEXT, GRAYED MENUITEM SEPARATOR POPUP "&Draw" BEGIN MENUITEM "&Rectangle", ID_TOOLS_DRAW_RECTANGLE MENUITEM "&Circle", ID_TOOLS_DRAW_CIRCLE, CHECKED MENUITEM "&Ellipse", ID_TOOLS_DRAW_ELLIPSE END MENUITEM SEPARATOR MENUITEM "&Erase All", ID_TOOLS_ERASE_ALL, INACTIVE END
MENUITEM "&About...", ID_ABOUT END
Clicking on menu item sends a WM_COMMAND message to its parent. WM_COMMAND message contains Menu item ID in the low word of WPARAM and handle in LPARAM.
The LoadMenu function loads the specified menu resource from the executable (.exe) file associated with an application instance.
HMENU LoadMenu(
HINSTANCE hInstance , //handle to the instance of the / LPCTSTR _lpMenuName / Menu Name */_ );
hInstance: Handle to the module containing the menu resource to be loaded.
lpMenuName: Pointer to a null-terminated string that contains the name of the menu resource. Alternatively, this parameter can consist of the resource identifier 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 menu resource. If the function fails, the return value is NULL. To get extended error information, call GetLastError.
You can specify default class menu for windows by assigning Menu name to the lpszMenuName parameter in window class.
wc. lpszMenuName= (LPCTSTR)IDR_MENU1; …………….. …………….. if(!RegisterClass(&wc)) { return 0; }
#define BUFFER_SIZE 128
TCHAR windowClassName[BUFFER_SIZE]; LoadString(hInstance, IDS_CLASS_NAME, windowClassName, BUFFER_SIZE); wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON)); wc.lpszMenuName = MAKEINTRESOURCE(IDR_FIRST_MENU); wc.lpszClassName = windowClassName
#define BUFFER_SIZE 128 TCHAR windowName[BUFFER_SIZE]; … … … LoadString(hInstance, IDS_APP_NAME, windowName, BUFFER_SIZE); hWnd = CreateWindow(windowClassName, windowName, ...
static int count; static BOOL bTimerStarted;
...... case WM_CREATE: count=0; bTimerStarted=FALSE
case WM_COMMAND: switch( LOWORD(wParam) ) { case ID_TIMER_START: SetTimer(hWnd, ID_TIMER, 1000, NULL); bTimerStarted=TRUE; hOurMenu = GetMenu(hWnd); EnableMenuItem(hOurMenu, ID_TIMER_START, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(hOurMenu, ID_TIMER_STOP, MF_BYCOMMAND | MF_ENABLED); DrawMenuBar(hWnd);
Case ID_TIMER_STOP:
KillTimer(hWnd, ID_TIMER); bTimerStarted=FALSE; hOurMenu = GetMenu(hWnd); EnableMenuItem(hOurMenu, ID_TIMER_STOP, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem(hOurMenu, ID_TIMER_START, MF_BYCOMMAND | MF_ENABLED); DrawMenuBar(hWnd); break;
case ID_FILE_EXIT: DestroyWindow(hWnd);
case WM_TIMER: switch(wParam) { case ID_TIMER: ++count; count %= 10; GetClientRect(hWnd, &rect); InvalidateRect(hWnd, &rect, TRUE); break; } break; }
TCHAR msg[10];
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps); wsprintf(msg, "Count: %2d", count); TextOut(hDC, 10, 10, msg, lstrlen(msg)); EndPaint(hWnd, &ps);
break;
case WM_DESTROY: if(bTimerStarted) KillTimer(hWnd, ID_TIMER); PostQuitMessage(0); break;