-3

I wonder if there is any way to somehow interact with windows that are currently open on a Windows system. I am interested in getting some of their properties, namely:

  • Location
  • Dimension
  • is in background?
  • possibly window title

Preferably, I would like to do that in Java but any suggestions are welcome.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Eugene S
  • 6,709
  • 8
  • 57
  • 91
  • 1
    See: [1](http://stackoverflow.com/questions/6091531/how-to-get-the-x-and-y-of-a-program-window-in-java) [2](http://stackoverflow.com/questions/11067484/get-titles-of-non-java-windows-in-java) [3](http://stackoverflow.com/questions/31312793/why-does-my-call-to-winapi-getwindowplacement-fail-using-jna) – theB Jun 24 '16 at 16:05

1 Answers1

1

A comment by theB linked to good resources for Java. I'll run through the relevant Windows APIs, in case you want to go native with C++.

To enumerate all the top-level windows in the system, use EnumWindows. You give it a callback function with the signature of EnumWindowsProc, so it will receive each window handle as the first parameter.

You can get the window location (in screen coordinates) and dimensions with the GetWindowRect function. Pass in the window handle you received and get an LPRECT (pointer to RECT) out.

To determine whether a window is maximized, use GetWindowPlacement and check the showCmd field of the WINDOWPLACEMENT structure you receive.

Finally, to get a window's caption, use GetWindowText. (As an aside, if you want to get the text of a control in another process, you'll need to send the WM_GETTEXT message yourself.)

Community
  • 1
  • 1
Ben N
  • 2,883
  • 4
  • 26
  • 49