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

    OnContextMenu in a doc/view

    Hi,

    On the view derived from CView I have created a window using CWnd::Create. The context menu is shown correct no matter if I right click on the created child window or inside the view window itself. But the command e.g. ID_EDIT_COPY do not work if right click on the child window but the view window.
    The child window eats the command.
    How can I redirect the command to the parent window? I tried to use OnCmdMsg but this does not work. (stack overflow)

    I already use OnCmdMsg in the view class because some commands should be sent to the child. I think that the command is sent from one OnCmdMsg to the other and back and....

    Any idea?

  2. #2
    Join Date
    Mar 2005
    Location
    Romania,Cluj-Napoca
    Posts
    1,073

    Re: OnContextMenu in a doc/view

    Please show us some code. ...post that two functions what are in the parent and in the child window(OnCmdMsg ).
    Please use code tags [code] [/code]

    We would change the world, but God won't give us the sourcecode..
    Undocumented futures are fun and useful....
    ___
    ______
    Gili

  3. #3
    Join Date
    Jul 2003
    Posts
    147

    Re: OnContextMenu in a doc/view

    I usually just do this:

    Code:
    CPoint pt;
    ::GetCursorPos(&pt);
    DWORD selection = popup_menu->TrackPopupMenu( 
    TPM_LEFTALIGN|TPM_RIGHTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD,
    pt.x,
    pt.y,
    this);
    view->PostMessage(WM_COMMAND,selection,0);
    


    GL
    "Live only for tomorrow, and you will have a lot of empty yesterdays today."

  4. #4
    Join Date
    Oct 2004
    Posts
    30

    Re: OnContextMenu in a doc/view

    Thanks for the help!


    pContextMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    CellPoint.x, CellPoint.y, this/*pWnd*/);

    The prblem was that I should ude "this" not the child window "pWnd".

  5. #5
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: OnContextMenu in a doc/view

    Quote Originally Posted by witte
    pContextMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    CellPoint.x, CellPoint.y, this/*pWnd*/);
    this means ur View otherwise use this

    Code:
    CWnd* pWndPopupOwner = this;
     pContextMenu->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON,
         CellPoint.x, CellPoint.y, pWndPopupOwner );
    If I Helped You, "Rate This Post"

    Thanks
    Guna

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