using
System.Runtime.InteropServices;
[DllImport(
"user32.dll"
, EntryPoint =
"SendMessage"
, SetLastError =
true
, CharSet = CharSet.Auto)]
private
static
extern
int
SendMessage(IntPtr hwnd,
uint
wMsg,
int
wParam,
int
lParam);
[DllImport(
"user32.dll"
, EntryPoint =
"FindWindow"
, SetLastError =
true
)]
private
static
extern
IntPtr FindWindow(
string
lpClassName,
string
lpWindowName);
[DllImport(
"user32.dll"
, EntryPoint =
"FindWindowEx"
, SetLastError =
true
)]
private
static
extern
IntPtr FindWindowEx(IntPtr hwndParent,
uint
hwndChildAfter,
string
lpszClass,
string
lpszWindow);
const
uint
BM_CLICK = 0xF5;
private
void
DoClick()
{
//下面的这些参数都可以用Spy++查到
string
lpszParentClass =
"#000000"
;
//整个窗口的类名,需要Spy++查询对应的窗口
string
lpszParentWindow =
"使命召唤10 xxxxxxx"
;
//窗口标题,这也是要Spy++去查
string
lpszClass_Submit =
"Button"
;
//需要查找的Button的类名,这里需要Spy++去查看是按钮还是图片什么的
string
lpszName_Submit =
"开始游戏"
;
//需要查找的Button的标题,这里需要Spy++去查看是按钮还是图片什么的
IntPtr ParenthWnd =
new
IntPtr(0);
IntPtr EdithWnd =
new
IntPtr(0);
//查到窗体,得到整个窗体
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
//判断这个窗体是否有效
if
(!ParenthWnd.Equals(IntPtr.Zero))
{
//得到Button,并触发它的Click事件
EdithWnd = FindWindowEx(ParenthWnd, (
uint
)EdithWnd, lpszClass_Submit, lpszName_Submit);
if
(!EdithWnd.Equals(IntPtr.Zero))
{
SendMessage(EdithWnd, BM_CLICK, 0, 0);
}
}
}
我看网上的资料说可以这么做:
取到button的句柄
然后用API SendMessage发送
WM_LBUTTONDOWN和WM_LBUTTONUP模拟点击
具体的代码怎么写呢?