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

Thread: PopUp Menu

  1. #1
    Join Date
    Apr 1999
    Posts
    5

    PopUp Menu

    I have a Tree view and list view similar to explorer in a MDI Application. In the List View I have a Popup menu displayed on click of the right mouse button.The problem is if I right click on any label of list view I get the Popup menu for the first time, but then if I click in another Label or same label area of List view I get the menu only in the second mouse click and not in the first click itself.i.e. I get the Popup menu for the first time without any problems but after that I get the Popup menu only after two mouse clicks.Please suggest a solution.


  2. #2
    Join Date
    Sep 1999
    Location
    Europe / Austria / Innsbruck
    Posts
    442

    Re: PopUp Menu

    Display the menu in response to the window message WM_CONTEXTMENU not in response to mouse click messages.


  3. #3
    Join Date
    Apr 1999
    Location
    NJ, USA
    Posts
    25

    Re: PopUp Menu

    You must doing TrackPopupMenu from OnRButtonDown(). That won't work , Instead you add the handler
    in OnRClick()
    message map looks like
    ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
    I am sending my code which I am using in ListView to show popup menu on Right click.
    void CItbListView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
    {
    // TODO: Add your control notification handler code here
    CWnd* pWnd = ((CTestprepApp* )AfxGetApp())->m_pMainWnd;
    CPoint point;
    GetCursorPos(&point);
    CPoint ptTemp = point;
    ScreenToClient(&point);
    m_pPopupMenu->CreatePopupMenu();
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDCTL ,"Add CTL");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMCTL ,"Remove CTL");
    m_pPopupMenu->AppendMenu(MF_SEPARATOR);
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDISC ,"Set ISC");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMISC ,"Remove ISC");
    m_pPopupMenu->AppendMenu(MF_SEPARATOR);
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDIGC ,"Set IGC");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMIGC ,"Remove IGC");
    m_pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,ptTemp.x,ptTemp.y,pWnd);
    m_pPopupMenu->DestroyMenu();
    *pResult = 0;
    }



  4. #4
    Join Date
    Apr 1999
    Location
    NJ, USA
    Posts
    25

    Re: PopUp Menu

    You must doing TrackPopupMenu from OnRButtonDown(). That won't work , Instead you add the handler
    in OnRClick()
    message map looks like
    ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
    I am sending my code which I am using in ListView to show popup menu on Right click.
    void CItbListView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
    {
    // TODO: Add your control notification handler code here
    CWnd* pWnd = ((CTestprepApp* )AfxGetApp())->m_pMainWnd;
    CPoint point;
    GetCursorPos(&point);
    CPoint ptTemp = point;
    ScreenToClient(&point);
    m_pPopupMenu->CreatePopupMenu();
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDCTL ,"Add CTL");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMCTL ,"Remove CTL");
    m_pPopupMenu->AppendMenu(MF_SEPARATOR);
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDISC ,"Set ISC");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMISC ,"Remove ISC");
    m_pPopupMenu->AppendMenu(MF_SEPARATOR);
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_ADDIGC ,"Set IGC");
    m_pPopupMenu->AppendMenu(MF_STRING ,ID_MENU_ITBLIST_REMIGC ,"Remove IGC");
    m_pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,ptTemp.x,ptTemp.y,pWnd);
    m_pPopupMenu->DestroyMenu();
    *pResult = 0;
    }



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