Click here to Skip to main content
13,003,150 members (59,397 online)
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 9 Oct 2005

Customizing the Non-client Window Area

, 18 Oct 2005
Rate this:
Please Sign up or sign in to vote.
Visual Basic offers virtually no way to customize the window outside of the client area; now you have at least one way.


The non-client area of a Visual Basic window includes the borders, title bar, menu bar, system menu icon, and some spacing between the non-client and client. The client area is simply the space given to you to place your controls. This project gives you the same control over the non-client area and is only limited to non-MDI windows. So, it is not for use for MDI Forms or MDI child forms.

With the attached code, you can easily dictate any appearance for the window. The appearance for the focused/active and unfocused/inactive windows are handled completely separately, enabling you to customize the window in both states. A compiled *.hlp file is provided in both downloads to help you navigate through the 100+ methods and properties.

How It Works

The project accomplishes this feat by controlling two key process.

First, the Client area is modified and shifted to allow space for the nonClient regions. This is pretty simple, in theory. We pre-measure everything that will go into the nonClient, calculate the client area by subtracting the window space available from the space reserved for the nonClient, and then shift the client area to the appropriate left-top coordinates in relation to the window.

Second, Visual Basic will overdraw our efforts, what it thinks is the nonClient, when specific window messages are received. The project needs to intercept these messages, process them, and occasionally let Visual Basic have them anyway. This project tricks Visual Basic into believing that it has no menu and no title bar by removing specific window styles just before those messages are received and then replacing them after those messages have been processed.

There is no way I could take into account all the possible custom scenarios you would want to implement. Therefore the DLL can be thought of as a standard nonClient painter. However, built-in functionality via the use of Implemented classes as callbacks allows the user to customize the nonClient beyond the capabilities of the DLL. You can request the DLL to pass some or most of the drawing responsibility to your code via the callbacks. The scalability of the DLL is one of its strongest "selling points," in my opinion.

The Title Bar

The title bar is pretty straightforward and is a rectangle overall. This can be positioned on any of the 4 sides of the rectangular window. When positioning it on the left or right edges, the font will be vertical, if possible. Use TTF fonts. Since we are controlling the nonClient area, we can do things like add extra buttons to the title bar with or without tooltips, arrange the buttons how we want, wrap the title bar caption, and simply toggle its visibility. There are no "rules" for vertical title bars, so I created a few: the typical system buttons will be towards the outer edge of the window; all buttons will be at the top of the window vs. the bottom; the system icon will remain near the beginning of the title bar caption. Placing near the bottom of the window looks awkward when the form is large/maximized, as the system icon can be quite far from the caption.

The Menu Bar

The menu bar is very similar to the title bar, basically rectangular. However, intercepting messages to mimic real menu bar behavior is complex. Again, VB will attempt to draw the menu bar or portions of it when specific messages are processed. The project does not draw images on the menu bar directly, that functionality is passed via class Implementation to the user. Since we are controlling the appearance, we can do simple things like hiding disabled menu items, change font styles and colors, format or shape the borders around selected or hovered menu items. The menu bar can also be aligned near the top of the window or near the bottom.

The Inset (Extra Space Created Within the NonClient)

The remaining area around the client area that does not include the menu bar or title bar, can also be modified to give more space on the nonClient. This extra space is like a frame for the client area. You can use this extra space to display custom sized borders, custom backgrounds, add text or other images. The project can forward you mouse actions related to those other objects placed on the nonClient (called tracking rectangles). One example in the download adds some text that mimics a hyperlink to the nonClient. When the mouse is over the text, the cursor changes and the text color changes. When you click on the text, you jump to a website.


Several other mini-projects are included so the DLL hopefully can be thought of as self-contained. Some of those others include window size restrictions, system tray icon(s), sub-classing other child windows, exporting/importing custom settings, and a graphics class that is never called by the DLL and only provided to assist the coder with common graphics/GDI related tasks.

The full source code has been provided. When unzipping the attachment, ensure you use the option to "Use Folder Names" and then simply open the *.vbg file and play. After you are satisfied, compile the DLL if you choose. A compiled DLL is provided in a separate zip file and if you prefer to use Visual Studio compiling your own, you should either register it yourself or reference it from your project (titled LaVolpe Custom Windows II) via the reference page or Browse button.

This project has been tested on 98, 2K, XP, NT4 (recently). It has been downloaded thousands of times via this site and other sites. Therefore, one can assume it was tested on ME and 95 also. Should you find errors or have strong recommendations for improvement, please send me a line.


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


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Generalgood job. Pin
catlikemice12-Jan-11 19:05
membercatlikemice12-Jan-11 19:05 
Question100 words or less? Pin
Chris Maunder17-Oct-05 9:41
adminChris Maunder17-Oct-05 9:41 
AnswerRe: 100 words or less? Pin
LaVolpe18-Oct-05 5:59
memberLaVolpe18-Oct-05 5:59 
GeneralGreat project! Pin
Richard Turnbull11-Oct-05 18:59
memberRichard Turnbull11-Oct-05 18:59 
GeneralRe: Great project! Pin
LaVolpe12-Oct-05 3:24
memberLaVolpe12-Oct-05 3:24 
GeneralThink I have an idea Pin
LaVolpe12-Oct-05 4:18
memberLaVolpe12-Oct-05 4:18 

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 | Terms of Use | Mobile
Web02 | 2.8.170626.1 | Last Updated 18 Oct 2005
Article Copyright 2005 by LaVolpe
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid