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;
}
}
查看全文
相关阅读:
【转】利用MVC模式开发Java应用程序[组图]
[转]JAVA三大框架SSH和MVC
二进制转十进制
MPlayerX For Mac白屏问题
输入法切换设置
【学习笔记】【C语言】选择结构-switch
【学习笔记】【C语言】选择结构-if
【学习笔记】【C语言】流程控制
Mac OS X中开启或关闭显示隐藏文件
Xcode6 模拟器不显示键盘
原文地址:https://www.cnblogs.com/crabo/p/591131.html
最新文章
Migrating from MapReduce 1 (MRv1) to MapReduce 2 (MRv2, YARN)...
Yarn 调度器Scheduler详解
linux 命令全名
kdevelop 是什么 什么鬼(windows系统非linux)
linux-centos7 gcc 简单使用
VMware12中CentOS7网络设置
VMware workstation 虚拟网络 三种上网区别
ts和nts的区别 (redis中碰到)
算法的复杂度
SQL server中让数据从1递增
热门文章
c#中combobox绑定数据库成功,但是获取到的值却是“system.data.datarowview”;
C#中提示框语句进行判断
C#中将一个整数中的数字逐个分离,并保存在数组中,如将123分离为1,2.3,保存在数组array中
【转】DBA需要的技能
微软推出的免费新书《Introducing Microsoft SQL Server 2012》
【转】刚入职程序员
【转】朴素贝叶斯分类器的应用
[转]美国的软件公司是什么样?---- 以Fog Creek为例
Java 专业人士必备的书籍和网站列表
【转】用java实例学习MVC模式
Copyright © 2011-2022 走看看