添加一个CPoint 返回类型的函数OnMouseMove,加入下面代码 void CMyView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); CString mystr; nx=point.x; ny=point.y; mystr.Format("坐标为:%d,%d",point.x,point.y); dc.TextOut(0,0,mystr); CView::OnMouseMove(nFlags, point); } CPoint CProgram4Dlg::testfun() { POINT point; //结构point ::GetCursorPos(&point); //api函数获取鼠标坐标 CPoint pt(point); //转换成CPOINT类 ClientToScreen(&pt); //将窗口内的偏移量天家到窗口的屏幕位置,这些值被转换成为实际屏幕值。 CString temp; temp.Format("x:%d,y:%d",pt.x,pt.y); MessageBox(temp); //用messagebox输出两个坐标,用语调试的,你可以删除。 return pt; //返回pt }
|