1》重载 virtual BOOL PreTranslateMessage(MSG* pMsg);
2》实现方法
<span style="font-size:16px;">BOOL Cpage1_listBox::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(WM_RBUTTONUP ==pMsg->message)
{
CPoint pt ;
CRect rtClient;
m_listBox.GetClientRect(&rtClient);
m_listBox.ClientToScreen(&rtClient);
INT iScrollPos= m_listBox.GetScrollPos(SB_VERT);
GetCursorPos(&pt);
int iSelect = (pt.y -rtClient.top+iScrollPos*m_listBox.GetItemHeight(0))/m_listBox.GetItemHeight(0);
//CString st=_T("");
//st.Format(_T("%d"),iSelect);
//::AfxMessageBox(st);
m_listBox.SetCurSel(iSelect);
m_listBox.RedrawWindow();
if(rtClient.PtInRect(pt)&&iSelect<m_listBox.GetCount())
{
CMenu MyMenu;
MyMenu.LoadMenu(IDR_SYSTEMFILE_POPMENU);
MyMenu.GetSubMenu(0)->TrackPopupMenu(TPM_RIGHTBUTTON,pt.x,pt.y,this,NULL);
MyMenu.Detach();//Detaches a Windows menu from a CMenu object and returns the handle
}
}
return CDialog::PreTranslateMessage(pMsg);
}</span>