zoukankan
html css js c++ java
通过Win API 模拟鼠标点击,使C# Java交互 (PART.2 Java部分)
Java部分:
调用:
ArrayList
<
QueueItem
>
li
=
new
ArrayList
<
QueueItem
>
();
li.add(
new
QueueItem(
"
WindowsForms10.Window.8.app3
"
,
"
采集系统
"
));
li.add(
new
QueueItem(
"
WindowsForms10.BUTTON.app3
"
,
"
选项
"
));
int
result
=
NativeWin32.ClickOnWindow(li);
System.
out
.print(result);
PINVOKE封装采用 NativeCall [
http://johannburkard.de/software/nativecall/
]
QueueItem,窗体查找时的节点定义.
public
class
QueueItem
{
public
String ClassName;
public
String WindowCaption;
public
boolean IsParent
=
true
;
public
QueueItem(String className,String windowCaption)
{
ClassName
=
className;
WindowCaption
=
windowCaption;
}
public
QueueItem(String className,String windowCaption,boolean isParent)
{
ClassName
=
className;
WindowCaption
=
windowCaption;
IsParent
=
isParent;
}
}
API
import com.eaio.nativecall.IntCall;
public
class
NativeWin32
{
public
static
Integer FindWindow(String sClassName,String sWindowName)
{
IntCall iCall
=
new
IntCall(
"
user32
"
,
"
FindWindowW
"
);
int
iRet
=
iCall.executeCall(
new
Object[]
{
sClassName,
sWindowName}
);
iCall.destroy();
return
new
Integer(iRet);
}
public
static
Integer FindWindowEx(Integer hwndParent,Integer hwndChildAfter,String sClassName,String sWindowName)
{
IntCall iCall
=
new
IntCall(
"
user32
"
,
"
FindWindowExW
"
);
int
iRet
=
iCall.executeCall(
new
Object[]
{
hwndParent,
hwndChildAfter,
sClassName,
sWindowName}
);
iCall.destroy();
return
new
Integer(iRet);
}
private
static
final
int
WM_GETTEXT
=
0x000D
;
private
static
final
int
WM_SETTEXT
=
0x000C
;
private
static
final
int
WM_CLICK
=
0x00F5
;
private
static
final
int
SW_MAXIMIZE
=
3
;
private
static
final
int
SW_SHOWNORMAL
=
1
;
private
static
Integer SendMessage(Integer hwnd,
int
msg,Integer wParam,String lParam)
{
IntCall iCall
=
new
IntCall(
"
user32
"
,
"
SendMessageW
"
);
int
iRet
=
iCall.executeCall(
new
Object[]
{
hwnd,
msg,
wParam,
lParam}
);
iCall.destroy();
return
new
Integer(iRet);
}
public
static
void
SetForegroundWindow(Integer hwnd)
{
IntCall iCall
=
new
IntCall(
"
user32
"
,
"
SetForegroundWindow
"
);
iCall.executeCall(
new
Object[]
{
hwnd}
);
iCall.destroy();
}
public
static
void
ShowWindow(Integer hwnd,
int
size)
{
IntCall iCall
=
new
IntCall(
"
user32
"
,
"
ShowWindow
"
);
iCall.executeCall(
new
Object[]
{
hwnd,
size}
);
iCall.destroy();
}
public
static
int
ClickOnWindow(java.util.ArrayList
<
QueueItem
>
queue)
{
int
result
=
-
1
;
Integer ParenthWnd
=
new
Integer(
0
);
Integer ChildhWnd
=
new
Integer(
0
);
QueueItem q
=
queue.
get
(result
+
1
);
//
查到窗体,得到整个窗体
ParenthWnd
=
FindWindow(q.ClassName,q.WindowCaption);
//
判断这个窗体是否有效
if
(ParenthWnd
!=
0
)
{
ShowWindow(ParenthWnd,SW_SHOWNORMAL);
SetForegroundWindow(ParenthWnd);
//
激活窗体
result
++
;
while
(result
+
1
<
queue.size())
{
q
=
queue.
get
(result
+
1
);
ChildhWnd
=
FindWindowEx(ParenthWnd,
0
,q.ClassName,q.WindowCaption);
if
(ChildhWnd
!=
0
)
{
if
(q.IsParent)
ParenthWnd
=
ChildhWnd;
result
++
;
}
else
break
;
}
//
得到了Button ? 触发它的Click事件
if
(ChildhWnd
!=
0
&&
queue.size()
==
result
+
1
)
{
SendMessage(ChildhWnd,WM_CLICK,
0
,
"
0
"
);
}
}
return
result;
}
}
查看全文
相关阅读:
GitLab使用公钥SSH key登录
P1305 新二叉树 /// 二叉树的先序遍历
P1030 求先序排列 /// 二叉树的遍历
P1020 导弹拦截 /// DP Dilworth定理 LIS、LDS优化
USACO 2008 November Gold Cheering up the Cows /// MST oj24381
USACO 2009 Open Grazing2 /// DP+滚动数组oj26223
Mid-Atlantic 2008 Lawrence of Arabia /// 区间DP oj21080
炮兵阵地 /// 状压DP oj26314
Post Office IOI 2000 /// 区间DP oj24077
Print Article /// 斜率优化DP oj26302
原文地址:https://www.cnblogs.com/crabo/p/591131.html
最新文章
bzoj3626 [LNOI2014]LCA
bzoj2243 [SDOI2011]染色
bzoj1984 月下“毛景树”
bzoj1036 [ZJOI2008]树的统计Count
HDU 1003 Max Sum
HDU 1702 ACboy needs your help again!(附加优先队列)
POJ 1611 The Suspects:并查集
矩阵
矩阵旋转
素数
热门文章
HDU 2544 最短路
小白实习趣事
去掉字符串内的空格
Ubuntu常用操作命令
MongoDB数据库去重
MongoDB数据导出
MySQL数据库导出
ubuntu安装mysql-connector-python
Redis基础操作
GitLab上传项目到新的分支
Copyright © 2011-2022 走看看