gpt4 book ai didi

c++ - 是否可以在隐藏窗口模拟鼠标移动和鼠标点击?

转载 作者:太空狗 更新时间:2023-10-29 20:40:17 26 4
gpt4 key购买 nike

那么有没有办法让我的 Win32 应用程序“认为”鼠标正在其窗口上移动并在实际窗口隐藏时进行一些点击(我的意思是 ShowWindow(hWnd, SW_HIDE);)?

我尝试用 PostMessageSendMessage 模拟鼠标移动,但到目前为止没有成功。

int x = 0;
int y = 0;
while (true)
{
SendMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
x += 10;
y += 10;
Sleep(100);
}

这可能吗?

最佳答案

是的,这是可能的。这是一个测试隐藏窗口:

#define UNICODE
#include <Windows.h>
#include <Strsafe.h>
#include <Windowsx.h>

LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM WParam, LPARAM LParam);

INT CALLBACK
WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
INT nCmdShow)
{
WNDCLASSEX WndClass;

ZeroMemory(&WndClass, sizeof(WNDCLASSEX));

WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.lpszClassName = L"HiddenWinClass";

if(RegisterClassEx(&WndClass))
{
HWND Hwnd;
MSG Msg;

Hwnd = CreateWindowEx(0, L"HiddenWinClass", L"Nan",
0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);

if(Hwnd)
{
UpdateWindow(Hwnd);
ShowWindow(Hwnd, SW_HIDE);
while(GetMessage(&Msg, 0, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
}

return 0;
}


LRESULT CALLBACK
WndProc(HWND Hwnd,
UINT Msg,
WPARAM WParam,
LPARAM LParam)
{
TCHAR Message[255];

switch(Msg)
{
case WM_MOUSEMOVE:
StringCbPrintf(Message, sizeof(Message), L"(%d, %d)",
GET_X_LPARAM(LParam), GET_Y_LPARAM(LParam));
MessageBox(NULL, Message, L"WM_MOUSEMOVE", MB_OK);
break;
default:
return DefWindowProc(Hwnd, Msg, WParam, LParam);
}

return 0;
}

这是你的代码:

#define UNICODE
#include <Windows.h>

int
main(int argc, char **argv)
{
HWND Hwnd;

if((Hwnd = FindWindow(L"HiddenWinClass", L"Nan")))
{
int x, y;

for(x = y = 0 ; ; x += 10, y += 10)
{
SendMessage(Hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
Sleep(100);
}
}

return 0;
}

效果很好。

关于c++ - 是否可以在隐藏窗口模拟鼠标移动和鼠标点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24701159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com