Docsity

Floating Popup Menus - Window Programming - Lecture Slides, Slides of Windows Programming

Partial preview of the text

Download Floating Popup Menus - 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

GetSubMenu()

Retrieves a handle to the drop-down menu or submenu

activated by the specified menu item

Floating popup menus

IDR_MENU_POPUP MENU DISCARDABLE BEGIN POPUP "Popup Menu" BEGIN MENUITEM "&Line", ID_POPUPMENU_LINE MENUITEM "&Circle", ID_POPUPMENU_CIRCLE MENUITEM "&Rectangle", ID_POPUPMENU_RECTANGLE POPUP "&Other" BEGIN MENUITEM "&Polygon", ID_OTHER_POLYGON MENUITEM "&Text Message", ID_OTHER_TEXTMESSAGE END END END

Only one drop-down starting with POPUP "Popup Menu"

Floating popup menus

HMENU hPopupMenu;

Bar hPopupMenu = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU_POPUP));

Bar hPopupMenu = GetSubMenu(hPopupMenu, 0);

Submenu numbering

0 1 2 3

WM_RBUTTONDOWN message

lParam: client-area coordinates of mouse cursor

low-word: x-coordinate high-word: y-coordinate

Floating popup menus: Main Window Procedure

POINTS pts; POINT pt; … … … … case WM_RBUTTONDOWN: Bar pts = MAKEPOINTS(lParam); BarS pt.x = pts.x; BarE pt.y = pts.y; Bar ClientToScreen(hWnd, &pt); Bar result = TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON, pt.x, pt.y, 0, hWnd, 0);

Mouse Tracking

Floating popup menus: Main Window Procedure

result = TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON, pt.x, pt.y, 0, hWnd, 0);

switch(result) { case ID_POPUPMENU_CIRCLE: MessageBox(hWnd, "Circle", "Popup clicked", MB_OK); break;

case ID_POPUPMENU_RECTANGLE: MessageBox(hWnd, “Rectangle", "Popup clicked", MB_OK); break;

} Docsity.com

Manipulating Menus at runtime

HMENU CreateMenu(VOID);

creates an empty menu

BOOL AppendMenu(… … …);

appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu.

BOOL InsertMenu (… … …);

inserts a new menu item into a menu, moving other items down the menu.

Manipulating Menus at runtime

BOOL ModifyMenu(… … …);

changes an existing menu item

Superseded by

BOOL SetMenuItemInfo(… … …);

changes an existing menu item

modified system/window menu

Right-click at the taskbar buttons

Most applications

MSDN library