[英]java JNA - find partial window title
I want to get a window by its title and then activate it. 我想按其标题获取一个窗口,然后将其激活。 The problem is that the FoundWindow
method searches on the all title. 问题是FoundWindow
方法搜索所有标题。 I would like to get a window by its partial title. 我想得到一个窗口的部分标题。
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef.HWND;
public class IsRunning {
public static void main(String[] args) {
HWND hwnd = User32.INSTANCE.FindWindow
(null, "Untitled - Notepad"); // window title
if (hwnd == null) {
System.out.println("Notepad window is not running");
}
else{
User32.INSTANCE.ShowWindow(hwnd, 9 ); // SW_RESTORE
User32.INSTANCE.SetForegroundWindow(hwnd); // bring to front
}
}
}
Instead of the string "Untitled - Notepad", I would like to search by "Untitled" only. 我只想按“无标题”搜索而不是字符串“无标题-记事本”。
Have a look on this answer "how to get list of all window handles in java using jna" . 看一下这个答案“如何使用jna获取Java中所有窗口句柄的列表” 。 You can then filter them on your own needs. 然后,您可以根据自己的需要过滤它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.