I´m trying to check if a Window, based on its title, is the Active Window. But the code that I used only works if I´m in Debug mode of Eclipse. If I run the program without breakpoints it doesn´t work. I´v tryed to delay the execution with a Thread sleep, but no success. Here is the code:
...
//Brings the window to Foreground
getUser32().SetForegroundWindow(gethWnd());
//Catch the Title
char[] buffer = new char[1024 * 2];
getUser32().GetWindowTextW(getUser32().GetForegroundWindow(), buffer, 1024*2);
System.out.println("Active window title: " + Native.toString(buffer));
String title = Native.toString(buffer);
//Checks if the Active Windows contains a little part of a String
if(!title.toLowerCase().contains(part.toLowerCase())) {
System.out.println("title: "+ title + "\n" + part + "\n" + 210);
System.exit(210);
}
...
Anyone colud help me?