StanChart
asked on
Question on using a CMenu
Hi,
I create a CMenu on the fly when the user right clicks on one of my controls. It's a simple cut/copy/paste menu.
CMenu *PopupMenu = new CMenu();
POINT DesktopPoint;
DesktopPoint.x = point.x;
DesktopPoint.y = point.y;
ClientToScreen(&DesktopPoi nt);
PopupMenu->AppendMenu(MF_S TRING, 1, "Copy");
PopupMenu->AppendMenu(MF_S TRING, 2, "Cut");
PopupMenu->AppendMenu(MF_S TRING, 3, "Paste");
BOOL bResponse =
PopupMenu->TrackPopupMenu( TPM_LEFTAL IGN, DesktopPoint.x, DesktopPoint.y, this);
The above code shows the menu but how do I know if they chose "Copy", "Cut", or "Paste"?
I create a CMenu on the fly when the user right clicks on one of my controls. It's a simple cut/copy/paste menu.
CMenu *PopupMenu = new CMenu();
POINT DesktopPoint;
DesktopPoint.x = point.x;
DesktopPoint.y = point.y;
ClientToScreen(&DesktopPoi
PopupMenu->AppendMenu(MF_S
PopupMenu->AppendMenu(MF_S
PopupMenu->AppendMenu(MF_S
BOOL bResponse =
PopupMenu->TrackPopupMenu(
The above code shows the menu but how do I know if they chose "Copy", "Cut", or "Paste"?
Oh, there even seems to be an easier way using 'TPM_RETURNCMD', see http://www.codeproject.com/menu/MenusForBeginners.asp#tpm
// some typical menu code using the TPM_RETURNCMD option:
CMenu menu;
CMenu *pSub = NULL;
// popup a menu to get the number of pages to display
VERIFY(menu.LoadMenu(IDR_P REVIEW_PAG ES));
pSub = menu.GetSubMenu(0);
// NOTE : If you need to enable or disable the menu items
// in this list based on the number of pages in your printout,
// you can either do it here before the menu is displayed, or write a
// handler for the WM_INITMENUPOPUP message and configure the
// enabled/disabled state at that point.
int command = pSub->TrackPopupMenu(
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
point.x,
point.y,
this);
switch (command)
{
case ID_PAGES_1PAGE :
m_Across = 1;
m_Down = 1;
m_nZoomOutPages = 1;
break;
case ID_PAGES_2PAGES :
m_Across = 2;
m_Down = 1;
m_nZoomOutPages = 2;
break;
case ID_PAGES_3PAGES :
m_Across = 3;
m_Down = 1;
m_nZoomOutPages = 3;
break;
case ID_PAGES_4PAGES :
m_Across = 2;
m_Down = 2;
m_nZoomOutPages = 4;
break;
case ID_PAGES_6PAGES :
m_Across = 3;
m_Down = 2;
m_nZoomOutPages = 6;
break;
case ID_PAGES_9PAGES :
m_Across = 3;
m_Down = 3;
m_nZoomOutPages = 9;
break;
default :
return;
}
// some typical menu code using the TPM_RETURNCMD option:
CMenu menu;
CMenu *pSub = NULL;
// popup a menu to get the number of pages to display
VERIFY(menu.LoadMenu(IDR_P
pSub = menu.GetSubMenu(0);
// NOTE : If you need to enable or disable the menu items
// in this list based on the number of pages in your printout,
// you can either do it here before the menu is displayed, or write a
// handler for the WM_INITMENUPOPUP message and configure the
// enabled/disabled state at that point.
int command = pSub->TrackPopupMenu(
TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
point.x,
point.y,
this);
switch (command)
{
case ID_PAGES_1PAGE :
m_Across = 1;
m_Down = 1;
m_nZoomOutPages = 1;
break;
case ID_PAGES_2PAGES :
m_Across = 2;
m_Down = 1;
m_nZoomOutPages = 2;
break;
case ID_PAGES_3PAGES :
m_Across = 3;
m_Down = 1;
m_nZoomOutPages = 3;
break;
case ID_PAGES_4PAGES :
m_Across = 2;
m_Down = 2;
m_nZoomOutPages = 4;
break;
case ID_PAGES_6PAGES :
m_Across = 3;
m_Down = 2;
m_nZoomOutPages = 6;
break;
case ID_PAGES_9PAGES :
m_Across = 3;
m_Down = 3;
m_nZoomOutPages = 9;
break;
default :
return;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I will suggest to create one Menu in Resource.
On Right Click Load and Display this menu.
You can eaisly add the message handler using the MFC class wizard then.
On Right Click Load and Display this menu.
You can eaisly add the message handler using the MFC class wizard then.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wNotifyCode = HIWORD(wParam); // notification code - 0 for menus
wID = LOWORD(wParam); // item, control, or accelerator identifier - the menu item ID
hwndCtl = (HWND) lParam; // handle of control
So, you'll receive 1, 2 or 3 in wID.