猫色色 发表于 2008-5-21 20:41

怎样才能实现,点击鼠标左键在鼠标的位置上输出鼠标坐标!

小弟在自学VC时遇到的题
要求单击鼠标右键,输出鼠标显示鼠标现在所在的坐标,而且当窗口大小改变或移动时,视图输出不变!
请哪位大哥告诉我怎么写!
我的想法是
void CCe3_5View::OnRButtonDown(UINT nFlags, CPoint point)
{
        // TODO: Add your message handler code here and/or call default
        CClientDC dc(this);
        int x=poitn.x;
        int y=poitn.y;
        dc.TextOut(point.x,point.y,x,y);
       
        CView::OnRButtonDown(nFlags, point);
}
可是行不通!
请问该怎么办

Arcticanimal 发表于 2008-5-21 22:39

dc.TextOut(point.x,point.y,x,y); // 这是做什么 ? TextOut MS没有这个重载类型
wchar_t wcBuffer[32];
memset(wcBuffer, 0, 32*sizeof(wchar_t));
StringCchPrintf(wcBuffer, 32, TEXT("X:  %d,  Y:  %d"), point.x, point.y);
CRect rc;
// Do somethig here to specify the position of text to be drawed
// For example, rc.left = ...; rc.top = ...;
dc.DrawText(wcBuffer, wcslen(wcBuffer), &rc, DT_RIGHT);

页: [1]

编程论坛