使用GetCursorPos()函数 假设是用pciture控件显示图片。 那么可以先改变控件的ID,然后定义一个CSTATIC 类型的变量如m_ctrlPic。 先得到当前鼠标坐标: CPoint point; GetCursorPos( &point ); 然后得到picture控件rect。 CRect rect; ::GetClientRect(m_ctrlPic.GetSafeHwnd(), &rect); 然后把当前鼠标坐标转为相对于rect的坐标。 ::ScreenToClient(m_ctrlPic.GetSafeHwnd(), &point); 然后判断该点坐标是否在rect内,在就显示 if(rect.PtInRect(point)) { CString strPos; strPos.Format("%d:%d", point.x, point.y); AfxMessageBox(strPos); } }
MFC中,关于得到鼠标在对话框上的坐标值
最新推荐文章于 2023-06-07 22:18:34 发布