wood burning stoves*
The moose likes Java in General and the fly likes get coordinates of all running forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "get coordinates of all running forms " Watch "get coordinates of all running forms " New topic
Author

get coordinates of all running forms

Matteo Lanzi
Greenhorn

Joined: Jan 10, 2009
Posts: 6
Hi everybody, i'm looking to a way to get all visible forms; can java enumerate all applications running and their forms to get coordinates ?

thanks
Teo
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Not without quite some native code. All it has access to are all window objects created by the current application.

You will need the "EnumWindows" call in C or Visual Basic to enumerate over all windows. Inside the enumerating function you can use "IsWindowVisible", "GetWindowText" and "GetWindowRect" to query the visibility, caption and bounds of the windows.

A bit of template code you may be able to use:

You call this as follows:
with xxx being a pointer to some structure you want to pass along to the GetWindowInformation function.

Here's also the code to create a java.awt.Rectangle from a RECT object (ignoring any possible error codes):


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Matteo Lanzi
Greenhorn

Joined: Jan 10, 2009
Posts: 6
Hi Rob, thanks a lot for your answer.
some little questions more;

so you mean in java i can use an int pointer to a window?

in java with (*env) i can dereference a pointer?

of course i have to make dll for win mac and linux, so can embed them in the project and still use an applet? I'd like to use an applet because this application have to works with a flex application

thanks again

Teo
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

First of all a warning: the code I posted is native C code, and works with Windows only. Mac and Linux have different ways which unfortunately I don't know, and is also determined to the windowing system used. X11 and Xorg may have different calls for this.

Matteo Lanzi wrote:so you mean in java i can use an int pointer to a window? [/url]

HWND is the same size as an int, so yes you can. Just remember to cast it back to HWND in native code.
However, I don't know the size of window handles in Mac or Linux, so you may have to end up with long instead and discard part of it when converting to HWND.

in java with (*env) i can dereference a pointer?

There are no pointers in Java. As I said at the top of this post, the code I posted is C code. With (*env) you can dereference a pointer in C, but not in Java.

of course i have to make dll for win mac and linux, so can embed them in the project and still use an applet? I'd like to use an applet because this application have to works with a flex application

If you use the same class(es) for Windows, Mac and Linux with just different native implementations, there is no problem. Just call System.loadLibrary and it will translate the library for you to a native file. For instance, searches for mywindows.dll in Windows, and for libmywindows.so in Linux (and probably Mac as well).
Matteo Lanzi
Greenhorn

Joined: Jan 10, 2009
Posts: 6
thanks for your support
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: get coordinates of all running forms
 
Similar Threads
MouseMotionListener
Doubts
getting applet's position in the screen
Why I can't change the JWindow's color?
Drag and Drop Problem