方法一:重载主函数的PreTranslateMessage(MSG* pMsg) 函数,通过message确定是哪个控件收到的消息。
if(WM_RBUTTONDOWN==pMsg->message)
if(pMsg->hwnd==m_clbPathShow.m_hWnd)
{
DWORD dwPos=GetMessagePos();
CPoint point(LOWORD(dwPos),HIWORD(dwPos));
CPoint temppt=point;
m_clbPathShow.ScreenToClient(&temppt);
BOOL _IsClient;
int _index=m_clbPathShow.ItemFromPoint(temppt,_IsClient);//该函数为列表框类函数,参数点坐标必须为客户区坐标
if (!_IsClient)
{
m_clbPathShow.SetCurSel(_index);
CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU_LBPUP));
CMenu *popup=menu.GetSubMenu(0);
ASSERT(popup!=NULL);
popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,this);//该点坐标确定菜单位置,必须是屏幕坐标
popup->DestroyMenu();
}
}
return CDialog::PreTranslateMessage(pMsg);
方法二:通过SetWindowLong函数改变控件的wndproc函数;