我建立了两个menu,一个是系统自己建立的,一个是IDR_RCLICKMENU (我用来弹出右键菜单的.其子菜单有两个ID分别是:ID_RMENU_INPUTMNY ,ID_RMENU_ACCOUNT)这个右键菜单是在CShowInfoView类中,是clistctrl类的。 在CShowInfoView中 我的代码:
void CShowInfoView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CListCtrl &oList = GetListCtrl();
CPoint pt(point);
ScreenToClient(&pt);
UINT nFlags = 0;
CMenu menu;
menu.LoadMenu(IDR_RCLICKMENU);
CMenu *pMenu = menu.GetSubMenu(0);
int nRetCode = pMenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_RETURNCMD, point.x, point.y, this);
}
我将ID_RMENU_INPUTMNY 映射为这个函数,但是电击子菜单的时候这个不能执行!
void CShowInfoView::OnRmenuInputmny()
{
// TODO: Add your command handler code here
CInputMnyDlg m_inputmny;
m_inputmny.DoModal();
}
void CShowInfoView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CListCtrl &oList = GetListCtrl();
CPoint pt(point);
ScreenToClient(&pt);
UINT nFlags = 0;
CMenu menu;
menu.LoadMenu(IDR_RCLICKMENU);
CMenu *pMenu = menu.GetSubMenu(0);
int nRetCode = pMenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_RETURNCMD, point.x, point.y, this);
}
我将ID_RMENU_INPUTMNY 映射为这个函数,但是电击子菜单的时候这个不能执行!
void CShowInfoView::OnRmenuInputmny()
{
// TODO: Add your command handler code here
CInputMnyDlg m_inputmny;
m_inputmny.DoModal();
}
OnRmenuInputmny() 没有执行就是说没有响应右键的消息
// ShowInfoView.cpp : implementation file
//#include "stdafx.h"
#include "局域网计算机管理系统.h"
#include "ShowInfoView.h"
#include "InputMnyDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CShowInfoView
extern int snum;IMPLEMENT_DYNCREATE(CShowInfoView, CListView)CShowInfoView::CShowInfoView()
{
}CShowInfoView::~CShowInfoView()
{
}
BEGIN_MESSAGE_MAP(CShowInfoView, CListView)
//{{AFX_MSG_MAP(CShowInfoView)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_RMENU_INPUTMNY, OnRmenuInputmny)
ON_COMMAND(ID_RMENU_ACCOUNT, OnRmenuAccount)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CShowInfoView drawingvoid CShowInfoView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}/////////////////////////////////////////////////////////////////////////////
// CShowInfoView diagnostics#ifdef _DEBUG
void CShowInfoView::AssertValid() const
{
CListView::AssertValid();
}void CShowInfoView::Dump(CDumpContext& dc) const
{
CListView::Dump(dc);
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CShowInfoView message handlers//DEL int CShowInfoView::OnCreate(LPCREATESTRUCT lpCreateStruct)
//DEL {
//DEL // 初始化列表
//DEL if (CListView::OnCreate(lpCreateStruct) == -1)
//DEL return -1;
//DEL return 0;
//DEL }//DEL void CShowInfoView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL // CPoint pt(point);
//DEL // CMenu menu;
//DEL // CPoint pos;
//DEL // GetCursorPos(&pos);
//DEL // menu.LoadMenu(IDR_RCLICKMENU);
//DEL // menu.TrackPopupMenu(TPM_RIGHTBUTTON,pos.x,pos.y,this);
//DEL // *pResult = 0;
//DEL } void CShowInfoView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
CListCtrl &oList = GetListCtrl();
CPoint pt(point);
ScreenToClient(&pt);
UINT nFlags = 0;
int nItem = oList.HitTest(pt, &nFlags);
if(nItem == -1) return;
SetItemState(nItem, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED);
CMenu menu;
menu.LoadMenu(IDR_RCLICKMENU);
CMenu *pMenu = menu.GetSubMenu(0);
// pMenu->AppendMenu(MF_STRING, 1000, oList.GetItemText(nItem, 0));
// pMenu->CheckMenuItem(0,MF_CHECKED|MF_BYPOSITION);
int nRetCode = pMenu->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_RETURNCMD, point.x, point.y, this);
}
void CShowInfoView::OnRmenuInputmny()
{
// TODO: Add your command handler code here
CInputMnyDlg m_inputmny;
m_inputmny.DoModal();
}