CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    Pop-Up menu MFC?

    I have created a dlg MFC app. Then I added a componenet/control, which was a pop-up menu to the dlg I created. So now my app runs great and when you right click it pops up a menu. How do I control this so that the menu only pop's up when I click on a button that I have added with the id of ID_OPTIONS? I know how to add the message handle for the ID_OPTIONS button. I just don't know how my program is currently calling this function? I can't figure out where my app is catching that messages of a right click and sending it to that function that was added when I added the component/control. Thanks for any help.


  2. #2
    Join Date
    Jul 1999
    Posts
    13

    Re: Pop-Up menu MFC?

    I will try to help you

    1. Do you want to display popup when user click on button-control IDC_OPTIONS ?



    void CYouDialog::OnOptions()
    {
    CRect r;
    GetDlgItem( IDC_OPTIONS )->GetWindowRect( r );

    CMenu menu;
    if (menu.LoadMenu(ID_POPUP_MENU))
    {
    CMenu* pPopup = menu.GetSubMenu(0);
    ASSERT(pPopup != NULL);
    pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, r.left, r.top,
    this/*or window which must handle this command*/);
    }
    }





    2. Yo want to display popup when user right-click on control IDC_OPTIONS ?



    void CYouDialog::OnContextMenu(CWnd* pWnd, CPoint point) // WM_CONTEXTMENU message handler
    {
    CRect r;
    GetDlgItem( IDC_OPTIONS )->GetWindowRect( r );

    if ( r.PtInRect( point ) ) // this condition can be replaced by next line:
    // if ( ::GetWindowLong( pWnd->GetSafeHwnd(), GWL_ID ) == IDC_OPTIONS )
    {
    CMenu menu;
    menu.LoadMenu( IDR_CONTEXT_MENU );
    menu.GetSubMenu(0)->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON,
    point.x, point.y, this );
    }
    }





    If any else, email me. Try to exclude the word "button" when you think "right-click or "left-click" - it is hard to understand for me (click button control or mouse button ?). If you are speak russian - simpify my life please


  3. #3
    Join Date
    Jul 1999
    Posts
    13

    Re: Pop-Up menu MFC?

    I will try to help you

    1. Do you want to display popup when user click on button-control IDC_OPTIONS ?



    void CYouDialog::OnOptions()
    {
    CRect r;
    GetDlgItem( IDC_OPTIONS )->GetWindowRect( r );

    CMenu menu;
    if (menu.LoadMenu(ID_POPUP_MENU))
    {
    CMenu* pPopup = menu.GetSubMenu(0);
    ASSERT(pPopup != NULL);
    pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, r.left, r.top,
    this/*or window which must handle this command*/);
    }
    }





    2. Yo want to display popup when user right-click on control IDC_OPTIONS ?



    void CYouDialog::OnContextMenu(CWnd* pWnd, CPoint point) // WM_CONTEXTMENU message handler
    {
    CRect r;
    GetDlgItem( IDC_OPTIONS )->GetWindowRect( r );

    if ( r.PtInRect( point ) ) // this condition can be replaced by next line:
    // if ( ::GetWindowLong( pWnd->GetSafeHwnd(), GWL_ID ) == IDC_OPTIONS )
    {
    CMenu menu;
    menu.LoadMenu( IDR_CONTEXT_MENU );
    menu.GetSubMenu(0)->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON,
    point.x, point.y, this );
    }
    }





    If any else, email me.
    Please try to exclude the word "button" when you think "right-click or "left-click"
    - it is hard to understand for me (click button control or mouse button ?).
    If you are speak russian - simpify my life please

    Best Regards, Eugene


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