Having a WinForms form with form border style set to Sizable
on Windows 8, the DesktopBounds
property tells the correct values:
In contrast, when having a form border style of FixedDialog
, the values are wrong:
On Windows XP, the values are always correct:
My question is:
How to get the real size of a Window including the complete non-client area?
Update 1:
Seems that it is related to this SO question. I'll try and see whether this would solve my issue here, too.
Update 2:
Just for completeness, here are the results from a VMware Windows 7:
Update 3:
Finally found a solution which involves using the DwmGetWindowAttribute
function together with the DWMWA_EXTENDED_FRAME_BOUNDS
value. I'll post an answer below.
I don't think "wrong" is quite the right way to put it.. you are seeing values you don't understand, but that's not always the same as wrong. The real question is what is the actual problem you are trying to solve by getting the window bounds?
Have you tried the Win32
GetWindowRect
method? I wonder what that shows.One hack you could try would be to detect the OS and account for these.
To determine the OS in C#: http://support.microsoft.com/kb/304283 (that sample doesn't mention Windows 8 specifically, but I assume the SDK has been updated for it)
To answer my own question, I finally found a solution which involves using the
DwmGetWindowAttribute
function together with theDWMWA_EXTENDED_FRAME_BOUNDS
valueThe answer was inspired by this source code which presents a function that seems to work on all system. The core is a function:
Full code is provided below: