Welcome! and rules
Joel on Software
borderless form removes system function
I am writing a C# application with border-style = NONE. The problem is that this also removes a lot of built in windows features from the form which I would like to get back. The key functions that are missing are the windows shortcuts (i.e. WINKEY + M = minimize all applications) and the application’s taskbar right-click functions (minimize, maximize, close).
This is my first post here, so thank you in advance for your help. If anyone knows how to reference these attributes and get them back your help would be greatly appreciated.
Friday, December 03, 2004
If you set the ControlBox property to False and FormBorderStyle to FixedSingle, you can get the Win-M shortcut, but not the context menu. You could add your own context menu to the form, but it won't work from the taskbar. I think if you don't have the top form border showing, then you also won't get the ControlBox (minimize, maximize, close, etc.) context menu, even if you haven't explicitly disabled it for the form.
Is there a reason the form has to be borderless?
Friday, December 03, 2004
I wanted to do something similar recently (for skinning a form) and ran into the same problem. As far as I could tell, getting the taskbar menu (and some related things) required the window to have a caption and border.
My solution to this was to accept that I'd have to have the caption and border but to override WndProc and use a little interop to shrink the size of these areas to zero. There were three steps involved:
1) Handle the WM_NCCALCSIZE message. Windows uses this to get the client rectangle. Set the client rectangle equal to the full window area and you'll get a similar effect as turning off the caption and border. Just a warning, WM_NCCALCSIZE can be a bit tricky to get working right so pay close attention to the documentation.
2) Handle WM_NCPAINT and WM_NCMOUSEMOVE (and maybe some others) to do nothing. Otherwise, the old caption ends up getting drawn randomly at times by the default window procedure. Interestingly, on XP with themes enabled, not intercepting WM_NCMOUSEMOVE resulted in the old non-themed style caption buttons getting drawn randomly.
3) Optionally handle WM_NCHITTEST if you want parts of your form to act like some of the non-client areas.
Saturday, December 04, 2004
Hide the caption etc using:
this.Region = new Region( rect );
(this specifies a mask through which to view the form)
calculate the rect using the form's ClientRectangle, etc.
Monday, December 06, 2004
Fog Creek Home