VC ListBox 右键菜单

 

BOOL CDocIndex::PreTranslateMessage(MSG* pMsg)
{
CWnd
* pWnd = GetDlgItem(IDC_FILE);
if( WM_RBUTTONDOWN == pMsg->message )
if( pWnd && pWnd->GetSafeHwnd() == pMsg->hwnd)
{
//AfxMessageBox("此处加菜单");
CMenu menu;
menu.CreatePopupMenu();
//动态创建弹出式菜单对象
menu.AppendMenu(MF_STRING,ID_TEST1,"Test1"); // 第一项菜单项
CPoint pt;
GetCursorPos(
&pt);
menu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y,
this);
menu.DestroyMenu();

}

 

 

在相应*Dlg.cpp中添加如下代码即可,别忘记在*Dlg.h文件中对函数声明哦。ID_TEST1应在Resource.h中定义,随便给不和其他变量重复的值即可。    

 

posted on 2010-06-28 10:43  Imagination  阅读(1488)  评论(0编辑  收藏  举报

导航