VC C++ API 模拟自动点击
::MessageBox(NULL,"1","1",MB_YESNO);HWNDhwnd1,hwnd2;hwnd1=::FindWindow(NULL,"1");hwnd...
::MessageBox(NULL,"1","1",MB_YESNO);
HWND hwnd1,hwnd2;
hwnd1=::FindWindow(NULL,"1");
hwnd2=::FindWindowEx(hwnd1,NULL,NULL,"是(Y)");
::::SetFocus(hWnd2);
UINT nCtrlID = ::GetDlgCtrlID(hWnd2);
::PostMessage(hWnd2, WM_COMMAND, (WPARAM)(BN_CLICKED << 16 | nCtrlID), (LPARAM)hWnd2);
::PostMessage(hWnd2,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );
::PostMessage(hWnd2,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));
::PostMessage(hWnd2,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));
return 0;
为什么不能模拟自动点击呢 ?
就自己弹出一个消息框 然后模拟点击确定 要求源代码
写完还可以加50分! 展开
HWND hwnd1,hwnd2;
hwnd1=::FindWindow(NULL,"1");
hwnd2=::FindWindowEx(hwnd1,NULL,NULL,"是(Y)");
::::SetFocus(hWnd2);
UINT nCtrlID = ::GetDlgCtrlID(hWnd2);
::PostMessage(hWnd2, WM_COMMAND, (WPARAM)(BN_CLICKED << 16 | nCtrlID), (LPARAM)hWnd2);
::PostMessage(hWnd2,WM_MOUSEMOVE, MK_LBUTTON, MAKELONG(0,0) );
::PostMessage(hWnd2,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));
::PostMessage(hWnd2,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));
return 0;
为什么不能模拟自动点击呢 ?
就自己弹出一个消息框 然后模拟点击确定 要求源代码
写完还可以加50分! 展开
2个回答
展开全部
楼上的回答很正确,在执行MessageBox函数之后,程序会一直等待你选择后才执行后面的代码。试试使用多线程来实现,一个主线程弹出一个消息框,一个线程点击确定。试试:
#include <windows.h>
DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
HWND hwnd1,hwnd2;
while(1)
{
Sleep(3000); // 每隔3秒去查看是否还有要点击的
hwnd1=::FindWindow(NULL,"1");
if (hwnd1 != NULL)
{
hwnd2=::FindWindowEx(hwnd1,NULL,NULL,"是(&Y)");
::PostMessage(hwnd2,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));
::PostMessage(hwnd2,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));
}
}
return 0;
}
int main(int argc, char *argv[])
{
::CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL); // 创建点击确定的线程
::MessageBox(NULL,"1","1",MB_YESNO);
return 0;
}
#include <windows.h>
DWORD WINAPI ThreadFunc( LPVOID lpParam )
{
HWND hwnd1,hwnd2;
while(1)
{
Sleep(3000); // 每隔3秒去查看是否还有要点击的
hwnd1=::FindWindow(NULL,"1");
if (hwnd1 != NULL)
{
hwnd2=::FindWindowEx(hwnd1,NULL,NULL,"是(&Y)");
::PostMessage(hwnd2,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(0,0));
::PostMessage(hwnd2,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(0,0));
}
}
return 0;
}
int main(int argc, char *argv[])
{
::CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL); // 创建点击确定的线程
::MessageBox(NULL,"1","1",MB_YESNO);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询