1

Is it possible to get sizes of all the open application windows using java?

Say for example I have 3 windows open on my laptop right now.. (google chrome, Microsoft word and Counter Strike in windowed mode)

So is it possible to get the dimension of each window size along with the running application name?

newbie2015
  • 581
  • 5
  • 29
  • 1
    You'll need a JNI/JNA based solution, something like [this](http://stackoverflow.com/questions/6091531/how-to-get-the-x-and-y-of-a-program-window-in-java) for example – MadProgrammer May 29 '15 at 05:40
  • Cool. Thanks. :) Exactly what I was looking for. – newbie2015 May 29 '15 at 05:44
  • I tried the code http://stackoverflow.com/a/6091597/4794952 but when I run the code I get an error The type com.sun.jna.win32.StdCallLibrary cannot be resolved. It is indirectly referenced from required .class files I downloaded the jar for stdcalllibrary from http://www.java2s.com/Code/Jar/j/Downloadjna324sourcesjar.htm But even after I am getting the same error What am I doing wrong? I searched the error online but didn't get any appropriate solution – newbie2015 May 29 '15 at 06:22
  • Did you download and link the JNA libraries? – MadProgrammer May 29 '15 at 06:23
  • Yes I downloaded the libraries from http://www.java2s.com/Code/Jar/j/Downloadjna324sourcesjar.htm and http://www.java2s.com/Code/Jar/j/Downloadjna330platformjar.htm – newbie2015 May 29 '15 at 06:26
  • And they are in your classpath for your project (also, you might want to include the error somewhere) – MadProgrammer May 29 '15 at 06:29
  • I tried the suggested method in the answer http://stackoverflow.com/a/2123192/4794952 Eclipse does not find SessionFactory. Is it a problem? However it does find Configuration. – newbie2015 May 29 '15 at 06:32
  • Yes I have added both the JARs in the buildpath using add external JARs. The error I am getting is (StdCallLibrary cannot be resolved to a type) on line [public interface User32 extends StdCallLibrary { ] and also (The type com.sun.jna.win32.StdCallLibrary cannot be resolved. It is indirectly referenced from required .class files) – newbie2015 May 29 '15 at 06:36
  • Okay, I download the `jna-platform-4.1.0.jar` and `jna-4.1.0.jar` from [GitHub](https://github.com/twall/jna), pasted the code from the linked example (linked the Jars into my IDE (Netbeans)) and ran it without an issue...I don't use Eclipse :P – MadProgrammer May 29 '15 at 06:39
  • I got it fixed :) Used http://www.java2s.com/Code/Jar/j/Downloadjna325jar.htm instead of http://www.java2s.com/Code/Jar/j/Downloadjna324sourcesjar.htm – newbie2015 May 29 '15 at 06:40
  • 1
    It's looking for a Window with the title `Document - WordPad` ... You might want to change that to what ever you're looking for ;) – MadProgrammer May 29 '15 at 06:44
  • Yes figured it out just after posting the comment. :P Thanks :) – newbie2015 May 29 '15 at 06:53

0 Answers0