我为Dlg类添加了WM_MOUSEMOVE消息响应函数 函数如下:void CMyDlg::OnMouseMove(UINT nFlags, CPoint point)
{
POINT p;
GetCursorPos(&p);
m_x =p.x;
m_y=p.y;
UpdateData(FALSE);
CDialog::OnMouseMove(nFlags, point);
}m_x、m_y 是我在对话框的2个编辑框关联的int变量 编译运行后 鼠标在对话框里面游动 可以显示坐标情况但是出了对话框后就不行了 怎么办啊 请教下高手
用构子或者获取桌面得DC才能绘制得GetCursorPos();
WindowFromPoint();
::GetDC() 返回的是桌面的表面窗口,在上面画当然能看到。
我是这么理解的 可能不是很准确,只是个人见解。。其实桌面是分 3个窗口的。。
HWND hParent = ::FindWindow( "Progman ", "Program Manager ");
ASSERT(hParent); HWND hShllDef = ::FindWindowEx(hParent, NULL, "SHELLDLL_DefView ", NULL);
ASSERT(hShllDef); HWND hDesk = ::FindWindowEx(hShllDef, NULL, "SysListView32 ", "FolderView ");
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
POINT p;
GetCursorPos(&p);
m_x =p.x;
m_y=p.y;
UpdateData(FALSE);
CDialogEx::OnTimer(nIDEvent);
}添加这个SetTimer(1,10,NULL); 你再测试下
{
// TODO: Add your message handler code here and/or call default
POINT pos;
GetCursorPos(&pos);
CString str;
str.Format("X:%d,Y:%d",pos.x,pos.y);
SetDlgItemText(IDC_EDIT1,str);
CDialog::OnTimer(nIDEvent);
}在OnInitDialog()中
SetTimer(1,100,NULL);