Source Code |
1 | VB 5 Custom Controls |   |
  |
vbAccelerator NeoCaption Component |
|
Skin the entire non-client area (titlebar, border, menu, control box and buttons) of your VB project by adding this component to your project |
NOTE:
this code has been superceded by the version at the new site.
|
Overview A Little History The first program out there I remember which offered any sort of customisation of the non-client area was Office 95, with those gradient caption bars. Although gradient captions aren't so much of interest now MS have rolled support into Win98/2000, they certainly were when Office 95 was launched. Suddenly everyone wanted a go at doing their own captions. How did you do it? And how come you could detach the menu bar in Office 95 - surely you could do this in your own app? After all, how hard could it be? Well, it turns out that drawing customised menu captions isn't easy at all. Windows just does not play fair - it continually redraws parts of the non-client area such as the Min/Max/Close buttons when you least expect it. Trying to reimplement a menu as a tear-off window whilst still allowing your app respond to Alt-Tab accelerator and the clicks in the Taskbar correctly is even more difficult. MS weren't very forthcoming on the subject of the Office 95 titlebar. The only Knowledge Base article (Q99046) on the subject coyly skirts around the topic, saying that whilst you could subclass WM_NCPAINT and WM_NCACTIVATE messages and then draw your own caption, it really isn't recommended; the whole idea of modifying the caption bar is foolish and outside the bounds of decent human behaviour (something even this author could agree with during the rash of windows which appeared at the time with primary red to neon blue gradients - very bad when encountered during a hangover). More interestingly, the Knowledge Base article somehow managed to totally avoid mentioning the fact that the Office implementation only worked at all because it was jam-packed with hacks. So we subclass two messages and do a little additional work afterwards? Yeah, right. Turns out you need to do all sorts of other somewhat abnormal things, such as removing the window style bit WS_VISIBLE during WM_SETCURSOR message processing and then putting it back again straight away afterwards. Anyway, luckily the nice people at Microsoft Systems Journal (MSJ) and Spy++ help you to understand what you really need to do. This sample brings together pieces of code from all sources, plus it adds some additional, VB specific workarounds to provide a full method for changing the size of the non-client area, plus drawing whatever you like into that region and providing an override to draw menus in a new style as well (this code is the basis for the vbAccelerator PopMenu2 object). Note: in the current version, this component does not work properly with MDI forms. When you maximise an MDI child, the system attempts to add new items to the menu for the control box and min/max/close buttons - which is not handled in the current code and causes a crash. A fix for this problem is under investigation. The vbAccelerator NeoCaption Component The DLL supplied with the download exposes two classes for public use:
Using the cNeoCaption Interface This should prove to be quite simple to use. There is one property to initialise the custom caption drawing and a number of others to control colours and fonts:
This starts processing with picResource(2) containing the titlebar and button graphics and picResource(3) containing the border graphics. The titlebar graphic is interpreted as having three sections: the active titlebar, the buttons and then the inactive titlebar. The numbers specify the coordinates and sizes of various components within the graphic. This picture demonstrates how these values are derived: The border picture consists of seven square images in-line which represent 2 x left hand border, bottom-left corner, bottom border, 2 x right hand border and finally the bottom-right corner. Stops the NeoCaption processing. Called automatically when the form unloads. The sample provided in the demonstration download show how to use the NeoCaption component to swap different skins at runtime and even how to remove a skin from a form. You could improve on these samples by putting the caption information into an XML file using the XML Property Bag component and loading it from there! Using the cNCCalcSize Object To gain lower level control over non-client area processing, you can implement the INCAreaModifier interface and attach directly to the cNCCalcSize object. Implementing the INCAreaModifier interface involves doing the following:
|
  | ||
  |
Back to top |
  |
NOTE:
this code has been superceded by the version at the new site.
|
About Contribute Send Feedback Privacy
|