在一个对话框panel上“List Box控键区域”,选中一行,单击右键,然后弹出菜单(在菜单项中做一些事情),看了一些例子不是很清楚, 请大家帮助一下,说说怎么来实现。

解决方案 »

  1.   

    首先是需要一个MENU,然后TrackPopupMenu
    The TrackPopupMenu function displays a shortcut menu at the specified location and tracks the selection of items on the menu. The shortcut menu can appear anywhere on the screen.To specify an area of the screen the menu should not overlap, use the TrackPopupMenuEx function. BOOL TrackPopupMenu(
      HMENU hMenu,         // handle to shortcut menu
      UINT uFlags,         // options
      int x,               // horizontal position
      int y,               // vertical position
      int nReserved,       // reserved, must be zero
      HWND hWnd,           // handle to owner window
      CONST RECT *prcRect  // ignored
    );
      

  2.   

    能说得具体点吗,比如怎么实现响应鼠标右键,不好意思, 以前没做过mfc开发。
      

  3.   

    CMenu menu;
    menu.LoadMenu(IDM_MENU1);
    menu.SubMenu(0).TrackPopupMenu(...)
      

  4.   

    void CGridCtrl::OnRButtonDown(UINT nFlags, CPoint point)
    {
    //MessageBox("right button down"); CMenu pp; //加载菜单
    pp.LoadMenu (IDR_MENU_ZKBH);
    CMenu* pSubMenu;
    //加载子菜单
    pSubMenu = pp.GetSubMenu(0);
    //显示菜单
    ClientToScreen(&point);
    pSubMenu->TrackPopupMenu(TPM_RIGHTBUTTON, point.x, point.y,this);
    pSubMenu->DestroyMenu();}
    正好有加载代码,也许有点作用。当然加载的前提是要求加入资源!三楼先!
      

  5.   

    这个问题和我的项目一样。
    1)需要一个MENU资源;
    2)创建一个自己的List Box类,比如CMyList类,加入下面的事件
    void CMyList::OnContextMenu(CWnd* pWnd, CPoint point) 
    {
     GetParent()->SendMessage(WM_UserStepEditPopUp,(WPARAM)pWnd,(LPARAM)&point);
    }
    在上面是事件中加一个自定义消息。
    #define WM_UserStepEditPopUp WM_USER+9
    3)把自定义消息引入对话框类。在加如下代码:
     LRESULT Cxxxx::OnEditPopUp(WPARAM wParam,LPARAM lParam)
    {    CPoint *point = (CPoint* )lParam; m_pOperList.ShowControls(HIDDEN_CONTROL); CMenu menu;
    SetFocus();
    if(menu.LoadMenu(MAKEINTRESOURCE(IDR_STEP_OPER)))
    {
    CMenu *pMenu = menu.GetSubMenu(1);
    if(NULL != pMenu)
    {
    pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTALIGN|TPM_RIGHTBUTTON,point->x,point->y,this);
    }
    }   return 0;
    }   就可以了!