15,979
社区成员
发帖
与我相关
我的任务
分享
BOOL CzuobiaoDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_LBUTTONDOWN && GetDlgItem(IDC_ShowImg)->GetSafeHwnd() == pMsg->hwnd )
OnLButtonDown(MK_LBUTTON, pMsg->pt); //在此传递点击部位在对话框中的坐标
return CDialog::PreTranslateMessage(pMsg);
}
void CzuobiaoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CRect rect_ctr;
(this->GetDlgItem(IDC_ShowImg))->GetWindowRect(&rect_ctr);//获取Picture控件相对屏幕左上角的坐标,
//存储到rect_ctr中
ScreenToClient(rect_ctr);//获取Picture控件相对对话框客户区左上角的坐标
point.x -= rect_ctr.left;//point获取的是鼠标相对对话框客户区左上角的坐标,减去rect_ctr.left和
point.y -= rect_ctr.top;//rect_ctr.top后,即为鼠标相对Picture控件左上角的坐标
}
void CDlgTmpDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
CPoint ptDest = point;
CRect rect_ctr[3];
ClientToScreen(&ptDest);
(GetDlgItem(IDC_PICTURE1))->GetWindowRect(&rect_ctr[0]);
(GetDlgItem(IDC_PICTURE2))->GetWindowRect(&rect_ctr[1]);
(GetDlgItem(IDC_PICTURE3))->GetWindowRect(&rect_ctr[2]);
if(isInRect(ptDest,rect_ctr[0]))
{
(GetDlgItem(IDC_PICTURE1))->ScreenToClient(&ptDest);
}
else if(isInRect(ptDest,rect_ctr[1]))
{
(GetDlgItem(IDC_PICTURE2))->ScreenToClient(&ptDest);
}
else if(isInRect(ptDest,rect_ctr[2]))
{
(GetDlgItem(IDC_PICTURE3))->ScreenToClient(&ptDest);
}
//CDialogEx::OnLButtonDown(nFlags, point);
}
BOOL CDlgTmpDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(pMsg->message == WM_LBUTTONDOWN && (GetDlgItem(IDC_PICTURE1)->GetSafeHwnd() == pMsg->hwnd
|| GetDlgItem(IDC_PICTURE2)->GetSafeHwnd() == pMsg->hwnd
||GetDlgItem(IDC_PICTURE3)->GetSafeHwnd() == pMsg->hwnd))
OnLButtonDown(MK_LBUTTON, pMsg->pt);
return CDialogEx::PreTranslateMessage(pMsg);
}
bool CDlgTmpDlg::isInRect( CPoint pt,CRect rect )
{
bool bReturn = false;
if(pt.x >= rect.left && pt.x <= rect.right &&pt.y >= rect.top && pt.y <= rect.bottom)
bReturn = true;
return bReturn;
}
不知道能不能满足要求,只适用与3个控件不重叠的情况