How to add a shortcut menu for vc ++ and a shortcut menu for vc
1. Create a new project
Ii. Edit menu Resources
1. Press Ctrl + R to add a Menu. Double-click the Menu icon. 2. Edit the Menu in the Menu editor.
4. Add code (red part)
Void CCMenuView: OnUpdateShow (CCmdUI * pCmdUI) {// TODO: Add your command update UI handler code hereMessageBox ("right-click the pop-up menu to test! ");} Void CCMenuView: OnRButtonDown (UINT nFlags, CPoint point) {// TODO: Add your message handler code here and/or call defaultCMenu menu; menu. loadMenu (IDR_MENU1); CMenu * pPopup = menu. getSubMenu (0); ClientToScreen (& point); pPopup-> TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, point. x, point. y, this); CView: OnRButtonDown (nFlags, point );}
V. Compilation
VII. Function Description
CMenu: TrackPopupMenu function declarationBOOL TrackPopupMenu (UINT nFlags, int x, int y, CWnd * pWnd, LPCRECT LPrECT = 0) nFlags: Position of the pop-up menu x: horizontal position of the pop-up menu y: vertical Position pWnd: The owner lpRect of the pop-up menu: a rect struct pointer containing rectangular coordinates. Function: displays a pop-up menu. If the function is successfully called, a non-zero value is returned; otherwise, zero is returned.