Click here to Skip to main content
14,031,046 members
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 31 May 2008
Licenced CPOL

Take Control of Your Non-Client-Area!

, 31 May 2008
Rate this:
Please Sign up or sign in to vote.
Learn how to control your non-client-area, while keeping all the stuff Vista puts on it.



Microsoft always seems to add some snazzy new features to programs like Office. Then, all the other developers run off to do it themselves, sell controls, etc. Well, there are plenty of ribbons out there, but there is something everyone seems to have forgotten. You can't draw on the title bar. So... how did Microsoft and those UserControl makers do it? That's what I wanted to know, because I needed to put stuff on the title bar. Googled everything I could think of, and ended up with an interesting C++ article about. After about a week, I came up with six lines of code that did the job. Never would have thought 6 lines = 1 week, eh? So, I suppose, you just want to make cool title bars now, I will get on with it now...


This article assumes you and the end user will both have Vista with Aero Glass. There is no code to check for this, or if you even have Vista, and I do not know what happens when you try on XP. The most complex part is the seven line WndProc, but we won't focus on the WinAPI much. Instead, I will assist you in solving the various issues this causes.

Using the code

To add this to your own application, you need to simply follow the tutorial below.

Open (or create a new) project. Select a Windows Forms Application, if it is a new project. After everything loads, click on your form once. Set the BackColor in the Properties window to Black. This allows it to be painted glassy. Now, add a reference to the Vista Controls Library. It is on CodePlex and included in my project zip above. Go back to the form editor and set your Form's BorderStyle to None. In the form Loaded event, add FormName.formborderstyle = System.Windows.Forms.FormBorderStyle.FixedSingle. Go to a new line in the Form's Load event, and add this code: VistaControls.DWM.DWMManager.EnableGlassSheet(Me). Now, for the most important part. Inside Public Class Formname, add Protected Overrides WndProc and hit Enter. Add the code below:

If M.Msg = &H83 then
    Dim point as new point(m.lparam.toint32)
    m.result = new intptr(-1)
end if

Put that in before MyBase.WndProc.

Now, run your application and you should have a title-less, icon-less, undraggable form with unresponsive title-bar buttons. Fantastic!

Because this an intermediate/advanced article, I am not going to go over all of this (you can find it in the solution above), but only the more difficult or unexpected parts. Please post a comment if you want help with a part I didn't cover. If it is not already open, you may want to open the project above for reference.

First, when the maximize option is clicked, it checks if the window is minimized, maximized, or normal. If it is normal, it maximizes, else it 'normalizes?' back into a window.

Second, there is a timer called checkButtons. This checks if Minimize or Maximize are disabled on the forums, and disables the appropriate button handler; however, this is one way. You cannot re-enable a button handler once it is disabled. What happens here is:

It checks if the buttons exist, and if they do not, moves the non-existent-buttons' handlers far off the screen (will be destroyed in the next update).

Now, for the reason I told you to set BorderStyle to None. This is because it gives you a more accurate picture of what your form will look like, because VB won't let you put stuff on the 'titlebar' in the designer.

Please consult the sample for anything I didn't cover, and feel free to post a comment asking about something in the sample you do not get.

Points of interest

The Desktop Window Manager must be extending the window's glass in some way in order to control the non-client area.

Also, it is strange how little code it takes once you know what you are doing.


None... Yet.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

o m n i
Software Developer (Junior) Omnicode Inc
United States United States
I am currently a small .Net Hobbyist developing applications for free.

You may also be interested in...


Comments and Discussions

Generalthe type vista control or soemthing is not defined Pin
AETCoder16-May-11 10:10
memberAETCoder16-May-11 10:10 
This project requires Vista, I got windoss 7 so?
AnswerRe: the type vista control or soemthing is not defined Pin
Tylor Lavoie17-May-11 6:29
memberTylor Lavoie17-May-11 6:29 
GeneralRe: the type vista control or soemthing is not defined Pin
kchinnam733-Feb-12 7:25
memberkchinnam733-Feb-12 7:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web04 | 2.8.190419.4 | Last Updated 1 Jun 2008
Article Copyright 2008 by o m n i
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid