C ++鼠标点击窗口中的某个点 [英] C++ mouse click on certain spot in window

查看:194
本文介绍了C ++鼠标点击窗口中的某个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的程序使用FindWindow来找到正确的窗口。我需要双击此窗口上的特定位置。



我通过将窗口放在屏幕上相同的位置来工作,但是如果我移动窗口,程序会尝试点击硬编码的位置已经提供,它不会工作。



以下是函数:

  void lobbyWindow(HWND main_client) 
{
// RECT arect;

// GetWindowRect(main_client,& arect);

SetCursorPos(748,294);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);

}

正如你所看到的,我将鼠标移到748,294双击。我想要做的是在main_client窗口中将鼠标设置为100,100,因此如果我移动main_client窗口,鼠标仍然会点击正确的位置。

解决方案

使用 SendInput() ,则可以使用标志相对于窗口移动光标 -



Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;


  1. 我可以模拟一个双鼠标单击窗口(i khow句柄)x,y使用SendInput?

  2. http://www.cplusplus .com / forum / windows / 97017 /


I have my function here working, but I am certainly going about it the wrong way.

My program uses FindWindow to find the correct window. I need to double click on a specific location on this window.

I made it work by always putting the window in the same location on the screen, but if I moved the window the program would try click on the hard-coded location I have provided and it would not work.

Here is the function:

void lobbyWindow(HWND main_client)
{
  //RECT arect;

   // GetWindowRect(main_client, &arect); 

    SetCursorPos(748,294);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}

As you can see I just move the mouse to 748,294 and double click. What I want to do is set the mouse to 100,100 in the main_client window, so if I move the main_client window the mouse still clicks on the correct spot.

解决方案

Use SendInput() instead, then you can use flags to move the cursor relative to the window -

Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;

  1. How i can simulate a double mouse click on window ( i khow handle) on x, y coordinate, using SendInput?
  2. http://www.cplusplus.com/forum/windows/97017/

这篇关于C ++鼠标点击窗口中的某个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆