mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0)?

cctime 2004-01-06 02:36:39
RECT rc;
GetWindowRect(hwnd, &rc);
x = rc.left+1,
y = rc.top+1,
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0)
为什么鼠标不能移到我想要的窗口hwnd上?
...全文
1666 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cctime 2004-01-07
  • 打赏
  • 举报
回复
::SetCursorPos()确实可以,不过为什么mouse_event()不行呢?
x,y都是相对屏幕的啊?
alfwolf 2004-01-06
  • 打赏
  • 举报
回复
其实要实现你的目的很简单:
void CMmmDlg::OnButton1()
{
// TODO: Add your control notification handler code here
RECT rc;
int x, y;
GetWindowRect(&rc);
x = rc.left+1;
y = rc.top+1;
::SetCursorPos(x,y);
}
cctime 2004-01-06
  • 打赏
  • 举报
回复
没错是左上角,但不是“最”左上角!
x,y都不是1吧?
alfwolf 2004-01-06
  • 打赏
  • 举报
回复
我用你的代码测试过了
鼠标确实移动到了屏幕的左上角。
函数如下:
void CMmmDlg::OnButton1()
{
// TODO: Add your control notification handler code here
RECT rc;
int x, y;
GetWindowRect(&rc);
x = rc.left+1,
y = rc.top+1,
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0);
}
cctime 2004-01-06
  • 打赏
  • 举报
回复
MSDN中说:
The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.

所以得到的是屏幕的坐标,ClinetToScreen()我早试过了,而且不用ClientToScreen()
鼠标也并没有移到最左上角,所以才奇怪
zhucde 2004-01-06
  • 打赏
  • 举报
回复
RECT rc;
GetWindowRect(hwn,&rc);
ClientToScreen(&rc);
int x = rc.left+1;
int y = rc.top+1;
SetCursorPos(x,y);
zhucde 2004-01-06
  • 打赏
  • 举报
回复
GetWindowRect(hwnd, &rc);
得到的rc是相对坐标,
它的左端顶端必然是0,
而mouse_event()用的却是屏幕坐标,
就会定位到屏幕左上角去
fzd999 2004-01-06
  • 打赏
  • 举报
回复
加在
x = rc.left+1;
前面
fzd999 2004-01-06
  • 打赏
  • 举报
回复
加上一行

ClientToScreen(&rc);
alfwolf 2004-01-06
  • 打赏
  • 举报
回复
因为mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, x, y, 0, 0)中x,y是屏幕坐标
估计你的鼠标移动到了屏幕的左上角了吧?
windyloft 2004-01-06
  • 打赏
  • 举报
回复
gz
everandforever 2004-01-06
  • 打赏
  • 举报
回复
SetCursorPos()

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧