简体   繁体   English

单击其他进程中其他窗口的按钮

[英]Click button of other window from other process

I'm new to WinAPI and I already created an empty window. 我是WinAPI的新手,并且已经创建了一个空窗口。 Now I want to make a little hack for the tutorial program of Cheat Engine. 现在,我想对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? 所以我的问题是: 是否可以将click命令发送到另一个进程的窗口? I have a handle of the window, a handle of the process and the process id (if it is not the same). 我有窗口的句柄,进程的句柄和进程ID(如果不相同)。

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. 抱歉,如果我的英语和/或某些技术术语不正确,但我是Win32的新手。


EDIT: I discovered, that the tutorial forbits every memory access, so my project will never work. 编辑:我发现,该教程禁止所有内存访问,因此我的项目将永远无法进行。 In addition, GetLastError(); 另外, GetLastError(); always returns ERROR_INVALID_PARAMETER when I try to install a second windows procedure for the tutorial program. 当我尝试为教程程序安装第二个Windows过程时,总是返回ERROR_INVALID_PARAMETER Do I have to use hProc instead of pid in SetWindowsHookEx (WH_CALLWNDPROC, &fnHook, NULL, pid); 我一定要使用hProc而不是pidSetWindowsHookEx (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 最简单的方法是使用SendMessage()发送WM_LBUTTONDOWN,然后将WM_LBUTTONUP消息发送到给定的窗口,例如

// 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. 更可靠的方法是调用SetWindowsHookEx(WH_MOUSE,...),然后通过给定的挂钩过程“播放”鼠标消息。 I haven't done that in a couple of decades so can't really talk about it in detail. 几十年来我还没有做到这一点,所以不能真正地详细讨论它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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