1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public
class
RobotTest {
public
static
void
main(String[] args){
test();
}
public
static
void
test(){
String path = RobotTest.
class
.getResource(
"dm.dll"
).getPath();
if
(path.startsWith(
"/"
)){
path = path.substring(
1
);
}
System.out.println(
"大漠插件路径:"
+path);
DLibrary dm = (DLibrary) Native.loadLibrary(path,DLibrary.
class
);
System.out.println(
"大漠插件:"
+dm);
long
hwnd = dm.FindWindow(
"SWT_Window0"
,
null
);
}
public
interface
DLibrary
extends
Library{
int
BindWindow(
int
hwnd,String display,String mouse,String keypad,
int
mode);
long
FindWindow(String type,String title);
}
}
|
1
2
3
4
5
6
7
8
9
10
11
|
大漠插件路径:F:/workspace/Test/bin/dm.dll
大漠插件:Proxy interface to Native Library
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'FindWindow': 找不到指定的程序。
at com.sun.jna.Function.
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:430)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:410)
at com.sun.jna.Library$Handler.invoke(Library.java:205)
at $Proxy1.FindWindow(Unknown Source)
at RobotTest.test(RobotTest.java:138)
at RobotTest.main(RobotTest.java:46)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
函数简介:
查找符合类名或者标题名的顶层可见窗口
函数原型:
long FindWindow(class,title)
参数定义:
class 字符串: 窗口类名,如果为空,则匹配所有. 这里的匹配是模糊匹配.
title 字符串: 窗口标题,如果为空,则匹配所有.这里的匹配是模糊匹配.
返回值:
整形数:
整形数表示的窗口句柄,没找到返回0
示例:
hwnd = dm.FindWindow("","记事本")
|