Click here to Skip to main content
Click here to Skip to main content

Vista Aero ToolStrip on Non-Client Area

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



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.


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


  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:


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


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;


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:


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)
            //Clear so Aero glass covers the area

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


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


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


About the Author

Jose Menendez Póo
Team Leader
Mexico Mexico
I'm in game programming now:

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


Comments and Discussions

QuestionNot support forecolor [modified] Pinmembertaqech@Gmail.com20-Jan-15 4:43 
QuestionDoesn't work without Aero? PinmemberQwertie19-Jun-12 8:57 
BugCannot drag window on second monitor Pinmemberchinswain7-Jun-12 23:55 
GeneralRe: Cannot drag window on second monitor PinmemberOzan Müyesseroğlu18-Nov-12 15:25 
GeneralRe: Cannot drag window on second monitor Pinmembergogogoggg16-Feb-13 11:18 
QuestionThe controls at top position of form move to title bar ,can't been showned. [modified] PinmemberMember 268840730-Dec-11 16:48 
GeneralMDI makes it white and undraggable PinmemberAETCoder16-May-11 13:12 
GeneralMy vote of 5 Pinmemberleesong3-Mar-11 4:09 
i love you ^^
GeneralMy vote of 5 PinmemberVB_ Coder22-Feb-11 8:12 
GeneralRe: My vote of 5 PinmemberAyden01-Oct-13 16:52 
GeneralMinimize/Maximize bug Pinmembercode17002-Jan-11 9:13 
QuestionHow to reduce distance from top and the left edge?? Pinmembervirtyaluk16-Oct-10 5:42 
QuestionHow to aero on client area but no Non-client area? Pinmemberstevenyoung8-Oct-10 3:05 
GeneralMy vote of 5 PinmemberMukit, Ataul13-Aug-10 9:30 
GeneralBlack bar bug Pinmemberscruffyfox6-Aug-10 4:45 
GeneralRe: Black bar bug [modified] Pinmember3of46-Sep-10 21:45 
GeneralMy vote of 5 PinmemberMikeDaMan25942-Jul-10 17:14 
GeneralMy vote of 5 PinmemberAlex Essilfie30-Jun-10 3:11 
GeneralArticle excellent! But... PinmemberEvgeniy Stepanow21-May-10 12:45 
QuestionHave DWM Draw the Window Icon? Pinmembersidneys17-May-10 11:47 
Generaldwmapi.dll missing PinmemberDivyesh Kharade26-Apr-10 3:07 
GeneralMDIContainer PinmemberSkippy II14-Apr-10 9:13 
QuestionWindow's context menu PinmemberDaHGBR6-Sep-09 5:41 
GeneralMinimize/Restore Resize bug Pinmemberplehxp29-May-09 7:46 
GeneralRe: Minimize/Restore Resize bug Pinmemberme6553218-Nov-09 18:25 
GeneralRe: Minimize/Restore Resize bug Pinmembercode17002-Jan-11 9:17 
GeneralRe: Minimize/Restore Resize bug PinmemberAETCoder16-May-11 13:11 
AnswerRe: Minimize/Restore Resize bug Pinmemberabdallah alsayed22-Dec-12 12:59 
Generalcool article PinmemberDonsw17-Feb-09 13:54 
GeneralFYI .. re: Localizable Pinmembermjmeans10-Feb-09 0:11 
QuestionUnusual bug Pinmemberultrafez0030-Jan-09 14:45 
AnswerRe: Unusual bug PinmemberJose M. Menendez Poó6-Feb-09 5:18 
GeneralAbout XP... Pinmemberbobert_smallgeek22-Jan-09 15:46 
GeneralRe: About XP... PinmemberJamie Nordmeyer9-Feb-09 5:07 
GeneralRe: About XP... PinmemberJose M. Menendez Poó9-Feb-09 5:12 
GeneralRe: About XP... Pinmemberbobert_smallgeek10-Feb-09 17:38 
GeneralNice. PinmemberJonathan C Dickinson20-Jan-09 20:22 
QuestionHow to RUN with XP or Win2k3 OS Pinmemberpcm_it18-Jan-09 19:20 
AnswerRe: How to RUN with XP or Win2k3 OS PinmemberJose M. Menendez Poó18-Jan-09 19:28 
GeneralRe: How to RUN with XP or Win2k3 OS PinmemberEdward11127-Jan-09 16:34 
GeneralRe: How to RUN with XP or Win2k3 OS PinmemberJose M. Menendez Poó27-Jan-09 16:43 
GeneralGlitching Pinmembersidneys118-Jan-09 4:40 
GeneralRe: Glitching PinmemberVCSKicks18-Jan-09 18:52 
GeneralRe: Glitching Pinmembertrackmz2k19-Jan-09 1:04 
GeneralRe: Glitching Pinmembersidneys119-Jan-09 4:30 
NewsRe: Glitching PinmemberJose M. Menendez Poó19-Jan-09 4:49 
GeneralRe: Glitching Pinmembermethodermis23-Feb-09 8:02 
GeneralRe: Glitching PinmemberCalifBreton30-Jun-09 8:47 
GeneralRe: Glitching PinmemberSteppenwolfe28-Jan-10 2:23 
GeneralYou need to get into WPF and Silverlight PinmvpSacha Barber17-Jan-09 22: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.150414.1 | Last Updated 8 Feb 2009
Article Copyright 2009 by Jose Menendez Póo
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid