Click here to Skip to main content
11,583,532 members (65,074 online)
Click here to Skip to main content

Vista Aero ToolStrip on Non-Client Area

, 8 Feb 2009 CPOL 132.6K 9.5K 217
Rate this:
Please Sign up or sign in to vote.
Place a ToolStrip on Aero's Glass non-client area.

NCBDemo

Introduction

When trying to figure out how to give the Ribbon an orb and the quick access toolbar, I found myself in trouble. I hope this example works for something you may need.

Background

Take a look to some Office app with a ribbon (Word, Excel, PowerPoint). There are some things that you might notice at first sight:

nonclient_002.jpg

  1. The orb is drawn half on the client area, half on the title bar
  2. The quick access tools are drawn (and sensed) on the title bar
  3. The title of the window is centered between the available space and the start of the caption buttons (minimize, maximize, close)

Using the code

Although it seems like the orb and the tools are drawn on the non-client area, they are not. This trick is done with one of the features of Vista's Desktop Window Manager (DWM).

How? Well, a regular window has a client area and a non-client area:

nonclient_003.jpg

But, a form with the trick done has no client area at all:

nonclient_004.jpg

So, why does the form look like it has a client area? A very well known trick: DwmExtendFrameIntoClientArea.

Turns out that when extending the frame into the client area, caption buttons (minimize, maximize, close) are drawn by default. To give life to these caption buttons, the DwmDefWindowProc function is called.

protected override void WndProc(ref Message m)
{
    ...

    int dwmHandled = Dwm.DwmDefWindowProc(m.HWnd, m.Msg, 
                         m.WParam, m.LParam, out result);

    if (dwmHandled == 1)
    {
        m.Result = result;
        return;
    }

    ... 

Now, we have to provide basic frame features like window moving and resizing. This is solved by handling the WM_NCHITTEST message on the WndProc. The return value for this message can specify which part of the frame the mouse is currently hitting. By a measurement of areas, the code returns the correct result:

  • Caption
  • North
  • South
  • East
  • West
  • NorthWest
  • NorthEast
  • SouthEast
  • SouthWest

Drawing the ToolStrip

To add a ToolStrip to the window, I just placed it as usual:

nonclient_005.jpg

and modified the render process so the ToolStrip gets no background:

public class NonClientAreaRenderer
        : ToolStripProfessionalRenderer
{

    protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
    {
        if (e.ToolStrip.IsDropDown)
        {
            base.OnRenderToolStripBackground(e);
        }
        else
        {
            //Clear so Aero glass covers the area
            e.Graphics.Clear(Color.Transparent);
        }
    }
    ...

And, there you go. A nice toolbar just on the non-client area, but you know, it's not the non-client area Smile | :)

History

  • 17 Jan. 09 - Original post.
  • 06 Feb. 09 - Focus bug fixed.

License

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

Share

About the Author

Jose Menendez Póo
Team Leader
Mexico Mexico
I'm in game programming now: https://itunes.apple.com/us/app/ugly-aliens-training-center/id859271884?ls=1&mt=8

Jose Manuel Menéndez Poó

- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is user interface usability.

Questions and stuff by twitter: @menendezpoo

Blog
menendezpoo.com

You may also be interested in...

Comments and Discussions

 
QuestionNot support forecolor Pin
taqech@Gmail.com20-Jan-15 3:43
membertaqech@Gmail.com20-Jan-15 3:43 
QuestionDoesn't work without Aero? Pin
Qwertie19-Jun-12 7:57
memberQwertie19-Jun-12 7:57 
BugCannot drag window on second monitor Pin
chinswain7-Jun-12 22:55
memberchinswain7-Jun-12 22:55 
GeneralRe: Cannot drag window on second monitor Pin
Ozan Müyesseroğlu18-Nov-12 14:25
memberOzan Müyesseroğlu18-Nov-12 14:25 
I've got no problem with moving form on second screen. Move and double click on top bar works.
GeneralRe: Cannot drag window on second monitor Pin
gogogoggg16-Feb-13 10:18
membergogogoggg16-Feb-13 10:18 
QuestionThe controls at top position of form move to title bar ,can't been showned. Pin
Member 268840730-Dec-11 15:48
memberMember 268840730-Dec-11 15:48 
GeneralMDI makes it white and undraggable Pin
AETCoder16-May-11 12:12
memberAETCoder16-May-11 12:12 
GeneralMy vote of 5 Pin
leesong3-Mar-11 3:09
memberleesong3-Mar-11 3:09 
GeneralMy vote of 5 Pin
VB_ Coder22-Feb-11 7:12
memberVB_ Coder22-Feb-11 7:12 
GeneralRe: My vote of 5 Pin
Ayden01-Oct-13 15:52
memberAyden01-Oct-13 15:52 
GeneralMinimize/Maximize bug Pin
code17002-Jan-11 8:13
membercode17002-Jan-11 8:13 
QuestionHow to reduce distance from top and the left edge?? Pin
virtyaluk16-Oct-10 4:42
membervirtyaluk16-Oct-10 4:42 
QuestionHow to aero on client area but no Non-client area? Pin
stevenyoung8-Oct-10 2:05
memberstevenyoung8-Oct-10 2:05 
GeneralMy vote of 5 Pin
Mukit, Ataul13-Aug-10 8:30
memberMukit, Ataul13-Aug-10 8:30 
GeneralBlack bar bug Pin
scruffyfox6-Aug-10 3:45
memberscruffyfox6-Aug-10 3:45 
GeneralRe: Black bar bug [modified] Pin
3of46-Sep-10 20:45
member3of46-Sep-10 20:45 
GeneralMy vote of 5 Pin
MikeDaMan25942-Jul-10 16:14
memberMikeDaMan25942-Jul-10 16:14 
GeneralMy vote of 5 Pin
Alex Essilfie30-Jun-10 2:11
memberAlex Essilfie30-Jun-10 2:11 
GeneralArticle excellent! But... Pin
Evgeniy Stepanow21-May-10 11:45
memberEvgeniy Stepanow21-May-10 11:45 
QuestionHave DWM Draw the Window Icon? Pin
sidneys17-May-10 10:47
membersidneys17-May-10 10:47 
Generaldwmapi.dll missing Pin
Divyesh Kharade26-Apr-10 2:07
memberDivyesh Kharade26-Apr-10 2:07 
GeneralMDIContainer Pin
Skippy II14-Apr-10 8:13
memberSkippy II14-Apr-10 8:13 
QuestionWindow's context menu Pin
DaHGBR6-Sep-09 4:41
memberDaHGBR6-Sep-09 4:41 
GeneralMinimize/Restore Resize bug Pin
plehxp29-May-09 6:46
memberplehxp29-May-09 6:46 
GeneralRe: Minimize/Restore Resize bug Pin
me6553218-Nov-09 17:25
memberme6553218-Nov-09 17:25 
GeneralRe: Minimize/Restore Resize bug Pin
code17002-Jan-11 8:17
membercode17002-Jan-11 8:17 
GeneralRe: Minimize/Restore Resize bug Pin
AETCoder16-May-11 12:11
memberAETCoder16-May-11 12:11 
AnswerRe: Minimize/Restore Resize bug Pin
abdallah alsayed22-Dec-12 11:59
memberabdallah alsayed22-Dec-12 11:59 
Generalcool article Pin
Donsw17-Feb-09 12:54
memberDonsw17-Feb-09 12:54 
GeneralFYI .. re: Localizable Pin
mjmeans9-Feb-09 23:11
membermjmeans9-Feb-09 23:11 
QuestionUnusual bug Pin
ultrafez0030-Jan-09 13:45
memberultrafez0030-Jan-09 13:45 
AnswerRe: Unusual bug Pin
Jose M. Menendez Poó6-Feb-09 4:18
memberJose M. Menendez Poó6-Feb-09 4:18 
GeneralAbout XP... Pin
bobert_smallgeek22-Jan-09 14:46
memberbobert_smallgeek22-Jan-09 14:46 
GeneralRe: About XP... Pin
Jamie Nordmeyer9-Feb-09 4:07
memberJamie Nordmeyer9-Feb-09 4:07 
GeneralRe: About XP... Pin
Jose M. Menendez Poó9-Feb-09 4:12
memberJose M. Menendez Poó9-Feb-09 4:12 
GeneralRe: About XP... Pin
bobert_smallgeek10-Feb-09 16:38
memberbobert_smallgeek10-Feb-09 16:38 
GeneralNice. Pin
Jonathan C Dickinson20-Jan-09 19:22
memberJonathan C Dickinson20-Jan-09 19:22 
QuestionHow to RUN with XP or Win2k3 OS Pin
pcm_it18-Jan-09 18:20
memberpcm_it18-Jan-09 18:20 
AnswerRe: How to RUN with XP or Win2k3 OS Pin
Jose M. Menendez Poó18-Jan-09 18:28
memberJose M. Menendez Poó18-Jan-09 18:28 
GeneralRe: How to RUN with XP or Win2k3 OS Pin
Edward11127-Jan-09 15:34
memberEdward11127-Jan-09 15:34 
GeneralRe: How to RUN with XP or Win2k3 OS Pin
Jose M. Menendez Poó27-Jan-09 15:43
memberJose M. Menendez Poó27-Jan-09 15:43 
GeneralGlitching Pin
sidneys118-Jan-09 3:40
membersidneys118-Jan-09 3:40 
GeneralRe: Glitching Pin
VCSKicks18-Jan-09 17:52
memberVCSKicks18-Jan-09 17:52 
GeneralRe: Glitching Pin
trackmz2k19-Jan-09 0:04
membertrackmz2k19-Jan-09 0:04 
GeneralRe: Glitching Pin
sidneys119-Jan-09 3:30
membersidneys119-Jan-09 3:30 
NewsRe: Glitching Pin
Jose M. Menendez Poó19-Jan-09 3:49
memberJose M. Menendez Poó19-Jan-09 3:49 
GeneralRe: Glitching Pin
methodermis23-Feb-09 7:02
membermethodermis23-Feb-09 7:02 
GeneralRe: Glitching Pin
CalifBreton30-Jun-09 7:47
memberCalifBreton30-Jun-09 7:47 
GeneralRe: Glitching Pin
Steppenwolfe28-Jan-10 1:23
memberSteppenwolfe28-Jan-10 1:23 
GeneralYou need to get into WPF and Silverlight Pin
Sacha Barber17-Jan-09 21:54
mvpSacha Barber17-Jan-09 21:54 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 8 Feb 2009
Article Copyright 2009 by Jose Menendez Póo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid