Simulate a click in a hidden window

I have a problem with C #,

I can simulate a click on the current window, but I would like to do this if the window is minimized or hidden.

Any ideas?

+2
c # click hidden simulate sendinput
Apr 23 2018-12-12T00:
source share
1 answer

Here is a complete working snippet that will give you a window handle, a target sub window, and send a message to this sub-sub.

#include "TCHAR.h" #include "Windows.h" int _tmain(int argc, _TCHAR* argv[]) { HWND hwndWindowTarget; HWND hwndWindowNotepad = FindWindow(NULL, L"Untitled - Notepad"); if (hwndWindowNotepad) { // Find the target Edit window within Notepad. hwndWindowTarget = FindWindowEx(hwndWindowNotepad, NULL, L"Edit", NULL); if (hwndWindowTarget) { PostMessage(hwndWindowTarget, WM_CHAR, 'G', 0); } } return 0; } 

At the moment, he will send the letter G to the โ€œUntitledโ€ notebook (open a new notebook, do nothing.

You can find the helper window using spy++ , which comes with visual studio.

Here is an example of using SendInput to send mouse events:

 #include "TCHAR.h" #include "Windows.h" int _tmain(int argc, _TCHAR* argv[]) { POINT pt; pt.x = 300; pt.y = 300; HWND hwndWindowTarget; HWND hwndWindowNotepad = FindWindow(NULL, L"Untitled - Notepad"); if (hwndWindowNotepad) { // Find the target Edit window within Notepad. hwndWindowTarget = FindWindowEx(hwndWindowNotepad, NULL, L"Edit", NULL); if (hwndWindowTarget) { PostMessage ( hwndWindowTarget, WM_RBUTTONDOWN, 0, (pt.x) & (( pt.y) << 16) ); PostMessage ( hwndWindowTarget, WM_RBUTTONUP, 0, (pt.x ) & (( pt.y) << 16) ); } } return 0; 

}

+2
Apr 23 2018-12-12T00:
source share
โ€” -



All Articles