本帖最后由 人造人 于 2021-11-9 23:28 编辑
比想象的要容易好多
模板在这了,自己照着这个改代码吧
target.c#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
MessageBox(NULL, "hello world!", "target", MB_OK);
return 0;
}
read_window_text.c#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <windows.h>
#define ID_MSGBOX_STATIC_TEXT 0x0000ffff
void read_target(void) {
pid_t pid = fork();
if(!pid) {
execl("./target.exe", "./target.exe", NULL);
exit(-1);
}
HWND hwnd = NULL;
char buff[1024];
while(!hwnd) {hwnd = FindWindow(NULL, "target"); usleep(100000);}
GetDlgItemText(hwnd, ID_MSGBOX_STATIC_TEXT, buff, 1024);
puts(buff);
HWND child = FindWindowEx(hwnd, 0, "Button", NULL);
RECT rect; GetWindowRect(child, &rect);
SendMessage(child, WM_LBUTTONDOWN, 0, MAKELPARAM((rect.right - rect.left) / 2, (rect.bottom - rect.top) / 2));
SendMessage(child, WM_LBUTTONUP, 0, MAKELPARAM((rect.right - rect.left) / 2, (rect.bottom - rect.top) / 2));
int status; waitpid(pid, &status, 0);
}
int main(void) {
size_t count = 5;
while(count--) {read_target(); usleep(500000);}
return 0;
}
|