Reputation: 11
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.
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.
Upvotes: 1
Views: 3762
Reputation: 22973
Have a look on this answer "how to get list of all window handles in java using jna". You can then filter them on your own needs.
Upvotes: 1