一: 实现方法:主要在WM_MouseMove消息内部实现坐标的获取
使用函数:GetCursorPos(&p)
二:测试代码
void CGetPointDlg::OnMouseMove(UINT nFlags, CPoint point)
{
/*以下为获取鼠标当前点在屏幕上面的坐标
(x,y)坐标是以整个屏幕为参照
*/
CString m_csPointScreen;
CPoint p;
GetCursorPos(&p);
m_csPointScreen.Format(_T("%d,%d"),p.x, p.y);
m_edit2.SetWindowText(m_csPointScreen);
/*以下为获取鼠标当前点在窗口(客户区坐标)上面的坐标
(x,y)坐标是以客户区原点(即窗口标题以下,左侧边框往右)为参照*/
CString m_csPointWindow;
m_csPointWindow.Format(_T("%d,%d"),point.x, point.y);
m_editPoint.SetWindowText(m_csPointWindow);
CDialog::OnMouseMove(nFlags, point);
}
三:测试效果