2

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?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
IOSJR
  • 31
  • 2
  • 8
  • Yes. This is a part of a bigger program. It´s part of a Robot fill program. – IOSJR Apr 15 '15 at 00:55
  • Define “doesn’t work”. It crashes? Show us the exception message. – Dour High Arch Apr 15 '15 at 00:59
  • The program always bring the Window to front, but without Debuging the Native.toString(buffer) returns empty, and the if clause becomes true and exit. – IOSJR Apr 15 '15 at 01:10
  • If I run with Breakpoints, Debuging, the title gets the corret asnwer of Native.toString(buffer) and the if clause becomes false, and the program goes on normal execution. In this way I can garante the corret Windows on top front . – IOSJR Apr 15 '15 at 01:11
  • For better help, consider creating and posting a [Minimal, Complete, and Verifiable Example Program](http://stackoverflow.com/help/mcve). We don't want to see your whole program, but rather you should condense your code into the smallest bit that still compiles, has no extra code that's not relevant to your problem, but still demonstrates your problem. You might very well solve the problem yourself by simply trying to isolate and expose the bug. – Hovercraft Full Of Eels Apr 15 '15 at 01:15

0 Answers0