-
May 4th, 2012, 12:56 PM
#1
MFC Context Menu
I am trying to implement a context menu when the MFC Dialog is clicked. I can get the menu up, but cannot get the individual sub-menu items in the menu to do anything when clicked. I used the wizard to add an event handler for the sub-menu items. I checked to make sure that the message map had entries for clicking in the sub-menu items. Clicking on the sub-menu items never hit the break points I placed in the generated functions I'm currently stuck at this point. Any help would be appreciated.,
-
May 4th, 2012, 01:49 PM
#2
Re: MFC Context Menu
How did you implement it?
Could you show your code (and, please, using Code tags!)?
Victor Nijegorodov
-
May 4th, 2012, 02:14 PM
#3
Re: MFC Context Menu
I added the menu in the resource editor.
To open the menu, i did the following:
<code>
CPoint mPointCurrent;
::GetCursorPos(&mPointCurrent);
CMenu mPopupMenu;
mPopupMenu.LoadMenu(IDR_MAP_CONTEXT);
CMenu *pContextMenu = mPopupMenu.GetSubMenu(0);
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON |
TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
mPointCurrent.x, mPointCurrent.y, ::GetActiveWindow(), NULL);
</code>
To create the event handlers for the individual sub-menu items, I right clicked the sub-menu item in the resource editor and selected add event handler. I then chose the dialog class that i wanted the event handler to be added to (the same dial that is opening the menu). It added a ON_COMMAND and ON_UPDATE_COMMAND_UI event handlers in the dialog class.
Thanks
-
May 4th, 2012, 02:36 PM
#4
Re: MFC Context Menu
- In CD forums the tags use [], not <>
- In what class did you implement the code you have posted?
- What was the your goal to pass in the ::GetActiveWindow API as the forth parameter of TrackPopupMenu?
Besides that ::GetActiveWindow() return value is HWND while TrackPopupMenu requires CWnd*, it is also not clear what was the active window while TrackPopupMenu has been called. - How and where (in what class) did you implement the message handlers for this menu items?
Victor Nijegorodov
-
December 19th, 2012, 07:38 AM
#5
Re: MFC Context Menu
Start Microsoft Visual C++ MFC Application named ControlContext
Create it as Dialog Box without the AboutBox
Set the Dialog Title to Context-Sensitive Menu on Controls
Add a button to dialog box. Change its ID to IDC_SUBMIT_BTN and its Caption to Submit
Add a check box to the dialog box. Change its ID to IDC_APPROVED_CHK and its Caption to Approved:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|