Docsity

Menu, Types of Menu Items - Window Programming - Lecture Slides, Slides of Windows Programming

Partial preview of the text

Download Menu, Types of Menu Items - Window Programming - Lecture Slides and more Slides Windows Programming in PDF only on Docsity!

LL ee cc tt uu rr ee

Review of Last Lecture

.rc resource file (text file containing many resource

statement)

Compile to .res file (using Resrouce Compiler)

Link with other files to make final EXE (using linker)

Menu

Types of Menu Items

drop-down menu

Popup menu

States of menu items

Checked Unchecked

States of menu items

Grayed

while selected, clicking it has no effect

Inactive

can not be selected

Separator

Example Menu

MENU resource definition statement IDR_MY_MENU MENU DISCARDABLE BEGIN POPUP "&Tools“ BBar BEGIN BBar MENUITEM "Write &Text", ID_TOOLS_WRITE_TEXT, GRAYED BBar MENUITEM SEPARATOR BBar POPUP "&Draw" BEGIN BBar MENUITEM "&Rectangle", ID_TOOLS_DRAW_RECTANGLE BBar MENUITEM "&Circle", ID_TOOLS_DRAW_CIRCLE, CHECKED BBar MENUITEM "&Ellipse", ID_TOOLS_DRAW_ELLIPSE END BBar MENUITEM SEPARATOR BBar MENUITEM "&Erase All", ID_TOOLS_ERASE_ALL, INACTIVE END BBar MENUITEM "&About...", ID_ABOUT END

T is mnemonic

Loading a menu

HMENU LoadMenu( HINSTANCE hInstance, // handle to module LPCTSTR lpMenuName // menu name or resource id );

  • Can be an integer ID or a string name of a menu
  • Call MAKEINTRESOURCE() macro to convert integer id

to a LPTSTR pointer.

In Win

all bits in high word of a 32-bit pointer are non-zero

But

all bits in high word of an integer < 65536 is 0

LPTSTR MAKEINTRESOURCE (WORD wInteger);

ASCII version of the macro

(LPSTR)((DWORD)((WORD)(i)))

Specifying a menu for a window CreateWindow(…,…, hMenu, …,…);

handle to menu HMENU loaded by LoadMenu()

Menu specified in CreateWindow() overrides default class

menu