1

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.

eebbesen
  • 5,070
  • 8
  • 48
  • 70
FarGore
  • 11
  • 1
  • 3
  • Have a look on this answer http://stackoverflow.com/questions/8717999/how-to-get-list-of-all-window-handles-in-java-using-jna which get a list of all window handles. You can then filter them on your own needs. – SubOptimal Jan 08 '15 at 12:03

1 Answers1

1

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.

Community
  • 1
  • 1
SubOptimal
  • 22,518
  • 3
  • 53
  • 69