TA的每日心情 | 开心 2017-8-10 09:38 |
|---|
签到天数: 147 天 连续签到: 1 天 [LV.7]常住居民III 初入江湖
 
- UID
- 14705
- 小七币
- 493
- 贡献
- 30
- 在线时间
- 224 小时
- 注册时间
- 2012-10-3
 
|
每秒模拟点击 按钮
mouse_event 的实现方法、- // sdk13.cpp : Defines the entry point for the application.
- //
- #include "stdafx.h"
- #include <tchar.h>
- int APIENTRY WinMain(HINSTANCE hInstance,
-
- HINSTANCE hPrevInstance,
-
- LPSTR lpCmdLine,
-
- int nCmdShow)
-
- {
- //API一日一练 第16天。 xqmsyk.com支持小七论坛。
- //love 小七论坛 By:hackbs
- while(1)
- {
- HWND Hfile=FindWindow(NULL,"小七论坛");
- if (!Hfile)
- {
- MessageBox(NULL,_T("未发现程序运行"),_T("温馨提示"),NULL);
- return 0;
- }
- HWND Button=FindWindowEx(Hfile,NULL,"Button",NULL);
- if(!Button)
- {
- MessageBox(NULL,"按钮没有被发现","温馨提示",NULL);
- return 0;
- }
-
- //用GetWindowRect得到按钮的大小尺寸
- RECT rect;
- GetWindowRect(Button,&rect);
-
- //计算按钮中心坐标 用SetCursoPos把鼠标移到中心点。
- POINT center;
- center.x = 0.5*(rect.left+rect.right);
- center.y = 0.5*(rect.top+rect.bottom);
- SetCursorPos(center.x, center.y);
-
-
-
-
-
-
- //鼠标在当前位置抬起
- mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
- mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
- //还原鼠标位置
- mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
-
- Sleep(1000);//过一秒 再执行后边的
- }
- return 0;
- }
复制代码 SendMessage的实现方法 、- #include "stdafx.h"
- #include <tchar.h>
- void KeybdEvent (BYTE bKeyCode,DWORD dwFlags)
- {
- keybd_event(bKeyCode, MapVirtualKey(bKeyCode, 0), dwFlags, 0);
- }
- int APIENTRY WinMain(HINSTANCE hInstance,
-
- HINSTANCE hPrevInstance,
-
- LPSTR lpCmdLine,
-
- int nCmdShow)
- {
- //API一日一练 第16天。 xqmsyk.com支持小七论坛。
- //love 小七论坛 By:hackbs
- while(1)
- {
- HWND Hfile=FindWindow(NULL,"小七论坛");
- if (!Hfile)
- {
- MessageBox(NULL,_T("未发现程序运行"),_T("温馨提示"),NULL);
- return 0;
- }
- HWND Button=FindWindowEx(Hfile,NULL,"Button",NULL);
- if(!Button)
- {
- MessageBox(NULL,"按钮没有被发现","温馨提示",NULL);
- return 0;
- }
-
- //点击 抬起。
- SendMessage(Button,WM_LBUTTONDOWN,1,0x1f0028);
- Sleep(50);
- SendMessage(Button,WM_MOUSEMOVE,1,0x1f0028);
- Sleep(50);
- SendMessage(Button,WM_LBUTTONUP,0,0x1f0028);
- KeybdEvent(VK_LBUTTON,KEYEVENTF_KEYUP);
- Sleep(1000);
- }
-
- return 0;
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
|