//在对话窗标题处实时显示客户区内鼠标的坐标
void CTestDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
str.Format("X:%d Y:%d", point.x, point.y); //格式化鼠标坐标点信息并保存到CString型变量str中
SetWindowText(str); //更新程序窗口Edit控件文本
CDialog::OnMouseMove(nFlags, point);
}
//单击鼠标时,显示鼠标在客户区内的坐标
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString str;
str.Format("x = %d, y = %d", point.x, point.y);
AfxMessageBox(str,MB_ICONQUESTION);
CDialog::OnLButtonDown(nFlags, point);
}
{
// TODO: Add your message handler code here and/or call default
lbPoint = point; //类成员函数,记录鼠标左键按下位置
CDialog::OnLButtonDown(nFlags, point);
}
亲,你给我的是屏幕坐标
ScreenToClient函数转换即可。