CRect rect;
GetClientRect(&rect);//获取客户区的大小
CPoint point;
GetCursorPos(&point);//获取当前指针的坐标(注意,这是屏幕的)
GetWindowRect(&rect);//获取客户区(客户区的左上角)相对于屏幕的位置
int _x=(point.x-rect.left)/rowWidth+1;//通过变换的到客户区的坐标
int _y=(point.y-rect.top)/colHeight+1; 看图示
</pre><pre class="cpp" name="code">
其实,我本来时要获取右击时的坐标,结果弄了半天弄成了上述的东西,来看一下弄好的吧
<pre>void Ctest_videoView::OnRButtonDown(UINT nFlags, CPoint point)
{
CView::OnRButtonDown(nFlags, point);
this->point.x = point.x;//给veiw类添加数据,得到右击获得的坐标
this->point.y = point.y;
}
void Ctest_videoView::OnMode32771()
{
// TODO: 在此添加命令处理程序代码
CRect rect;
CPoint point;
GetCursorPos(&point);//获取当前指针的坐标(注意,这是屏幕的)
GetWindowRect(&rect);//获取客户区(客户区的左上角)相对于屏幕的位置
int _x = (point.x - rect.left) ;//通过变换的到客户区的坐标
int _y = (point.y - rect.top) ;
CString str;
str.Format(_T("右击位置(%d,%d),/n当前位置(%d,%d)"),this->point.x,this->point.y, _x, _y);
//这样弹出右击坐标显示和当前坐标显示
AfxMessageBox(str);
}
图示:
<img src="https://img-blog.csdn.net/20150712160229940?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />