if( OxRT.PtInRect( pt ) ) //判断鼠标是否在当前条目所占的矩形区域当中 { return TRUE; //如果确定是第一行,直接返回 } } return CDialog::PreTranslateMessage(pMsg); }其中需要特别注意的是GetItemRect( 0, OxRT,LVIR_BOUNDS ); 这个函数的第三个参数: 意思是(MSDN): //Portion of the list view item for which to retrieve the bounding rectangle. It can be one of these values://LVIR_BOUNDS Returns the bounding rectangle of the entire item, including the icon and label.//LVIR_ICON Returns the bounding rectangle of the icon or small icon.//LVIR_LABEL Returns the bounding rectangle of the item text.
BOOL C**Dlg::PreTranslateMessage(MSG* pMsg)
{
if( WM_LBUTTONDOWN == pMsg->message ) //截获对话框的右键消息
{
CListCtrl* listWnd = ( CListCtrl* )GetDlgItem( IDC_LIST1 ); //取得CListCtrl控件的窗口句柄
CPoint pt; ::GetCursorPos( &pt ); //取得鼠标的屏幕坐标
CRect OxRT;
listWnd->GetItemRect( 0, OxRT,LVIR_BOUNDS ); //取得条目0(第一行的区域)
listWnd->ClientToScreen(&OxRT); //转换为屏幕坐标
if( OxRT.PtInRect( pt ) ) //判断鼠标是否在当前条目所占的矩形区域当中
{
return TRUE; //如果确定是第一行,直接返回
}
} return CDialog::PreTranslateMessage(pMsg);
}其中需要特别注意的是GetItemRect( 0, OxRT,LVIR_BOUNDS ); 这个函数的第三个参数:
意思是(MSDN):
//Portion of the list view item for which to retrieve the bounding rectangle. It can be one of these values://LVIR_BOUNDS Returns the bounding rectangle of the entire item, including the icon and label.//LVIR_ICON Returns the bounding rectangle of the icon or small icon.//LVIR_LABEL Returns the bounding rectangle of the item text.