CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2012
    Posts
    2

    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.,

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Context Menu

    How did you implement it?
    Could you show your code (and, please, using Code tags!)?
    Victor Nijegorodov

  3. #3
    Join Date
    May 2012
    Posts
    2

    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

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: MFC Context Menu

    1. In CD forums the tags use [], not <>
    2. In what class did you implement the code you have posted?
    3. 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.
    4. How and where (in what class) did you implement the message handlers for this menu items?
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2012
    Location
    Fremont,CA
    Posts
    37

    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
  •  





Click Here to Expand Forum to Full Width

Featured