How to send a mouse click event to a hidden window?

后端 未结 2 1689
南方客
南方客 2021-01-06 22:18

Recognising that a bit of interop may be required, how do I send a mouse click event to a window that is currently not being displayed? I have an application that is running

相关标签:
2条回答
  • 2021-01-06 22:27

    Use Spy++ to find out what Windows messages are sent to the window when it's shown and you physically click it with the mouse, and then use SendMessage to send those messages directly.

    0 讨论(0)
  • 2021-01-06 22:32

    If you can get the HWND of the window, it's pretty easy. Use PostMessage() with WM_LBUTTONDOWN for a left click.

    Example: click on position 10,10 (untested, C)

    HWND hWnd = (hwnd of window)
    WORD mouseX = 10;
    WORD mouseY = 10;
    PostMessage(hWnd,WM_LBUTTONDOWN,0,MAKELPARAM(mouseX,mouseY));
    
    0 讨论(0)
提交回复
热议问题