【发布时间】:2015-01-08 11:59:26
【问题描述】:
我想通过标题获取一个窗口,然后激活它。问题是FoundWindow 方法搜索所有标题。
我想通过部分标题获取一个窗口。
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
}
}
}
我想只搜索“Untitled”而不是字符串“Untitled - Notepad”。
【问题讨论】:
-
看看这个答案stackoverflow.com/questions/8717999/… 得到所有窗口句柄的列表。然后,您可以根据自己的需要过滤它们。