Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine ACTUAL windows form size (with all nonclient elements) when running Aero?

I'm trying to position my form precisely above the taskbar. Unfortunately my efforts are hampered by the fact that this.Height on my form returns a value which is 10 pixels smaller than the actual form (with all the borders, title bar, etc). I'm running Windows 7 with Aero. When Aero is turned off (and the borders are thinner), all works as expected. The form border style is FixedSingle. I don't want to implement Aero-specific hacks. What can I do to get the correct height?

like image 627
Vilx- Avatar asked Jan 12 '12 16:01

Vilx-


1 Answers

Yes, Aero lies about the window size returned by GetWindowRect(). It is a rather important appcompat hack, without it far too many programs would have a client area that's too small. Unfortunately there's neither an API call nor a manifest entry that can be used to turn off the lie. The only way is to set the Windows version in the EXE header and mark it Vista compatible.

You can do so with Editbin.exe in a postbuild event:

set pathsave=%path%
set path=$(devenvdir);$(devenvdir)..\..\vc\bin
editbin.exe /subsystem:windows,6.0 "$(targetfilename)"
set path=%pathsave%

Beware that your program will not run in XP anymore after this.


UPDATE: this is now done by default in VS2012 and up when you target .NET 4.5

like image 130
Hans Passant Avatar answered Nov 19 '22 17:11

Hans Passant