简体   繁体   中英

Click button of other window from other process

I'm new to WinAPI and I already created an empty window. Now I want to make a little hack for the tutorial program of Cheat Engine. I already know, how to change values in the memory of other processes. But as soon as I changed a value in the tutorial program, I'm forced to click a "next" button. So my question is: Is it possible to send a click command to a window of another process? I have a handle of the window, a handle of the process and the process id (if it is not the same).

The only thing I know about the buttons is, that their text is always "next".

Here is a shortened version of my code:

HWND hWnd = FindWindow (NULL, L"Window's title");               // Search startup window

DWORD pid;                                                      // Get process id
GetWindowThreadProcessId (hWnd, &pid);

HANDLE hProc = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);    // Get access to process

DWORD base = 0x789ABCDE;                                        // Get value of static pointer
ReadProcessMemory (hProc, &base, &base, 4, NULL);

WORD offset = 0xBCDE;                                           // Write to memory
WriteProcessMemory (hProc, (void *)(base + offset), (void *)5000, 4, NULL);

// Send click command (???)

Sorry, if my english and/or some technical terms aren't correct, but I'm new to Win32.


EDIT: I discovered, that the tutorial forbits every memory access, so my project will never work. In addition, GetLastError(); always returns ERROR_INVALID_PARAMETER when I try to install a second windows procedure for the tutorial program. Do I have to use hProc instead of pid in SetWindowsHookEx (WH_CALLWNDPROC, &fnHook, NULL, pid); ?

The simplest way to do this is to use SendMessage() to send an WM_LBUTTONDOWN and then a WM_LBUTTONUP message to the given window, something like

// x, y are the coords
SendMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
SendMessage(hWnd, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));

This may or may not work in your particular case; if the spot that you're trying to click is actually in a child window or a popup you've just "clicked" the wrong window, and a lot of apps rely on other messages.

The more reliable way to do it is to call SetWindowsHookEx(WH_MOUSE, ...), and "play" the mouse messages through the given hook procedure. I haven't done that in a couple of decades so can't really talk about it in detail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM