I want to get only the visible part of the window in windows, as a region.
Want to get only the area that is seen by the user. Programmatically, of course. Here is an example. I have the following window composition:
+------------------------------------------+
| |
| +=============+ |
| | | |
| | A +--------------------------+
| | | |
| C | | B |
| | +--------------------------+
| | | |
+-----------| |----------------+
| |
+-------------+
Let's say that I am interested only in window A. Then what I would need is a handle to a region which would look like this:
+=============+
| |
| A +-----+
| |
| |
| +-----+
| |
| |
| |
+-------------+
Alternatively, I should be able to obtain the region of any other window in the following manner.
So far, I used this guide: http://blogs.msdn.com/b/oldnewthing/archive/2003/09/02/54758.aspx
And I agree that GetClipBox returns 0, 1, 2 or 3 if you have, accordingly, 0 -> Error, 1 for NULLREGION(the resulting rgn is invisible to the user), 2 -> SIMPLEREGION, and 3 for COMPLEXREGION. So, far, I need the complex region.
Master Question: But how do I get its coordinates and dimensions ?
(Added Info)
Is it possible to reconstruct a COMPLEXREGION (That was created by the OS, not me) to simple REGIONS of which it is composed. Feng Yuan suggests you can't:
http://www.codeguru.com/forum/archive/index.php/t-126543.html
(Added Info)
So, is there a way to find the region of A and translate it to a PolyPath or a nice geometric figure having the coordinates of its corners ?
I use JNA (Java) , by the way, but a C# or .VB code solving the same problem would be sufficient.
Cheers.
You can enumerate all desktop windows, plus all monitors, and combine their rectangles. I'm not sure if there is a better way.
Note that Windows "lies" about the exact dimensions of windows these days (the Aero window border is slightly bigger than actually reported unless you set a special flag).
Also note that windows can have see-through portions defined by each application (in addition to the see-through window borders you always have under Aero).
You also need to be careful on high-DPI systems where Windows "lies" to your app about coordinates unless you go out of your way to flag it as DPI-aware.
And also note that even an "invisible" window can be visible via the Taskbar, Alt-Tab or Flip3D thumbnails feature of Aero... So, really, on Vista and Windows 7 with DWM enabled, the answer is that your window is potentially always completely visible. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With