Click here to Skip to main content
Licence 
First Posted 28 Apr 2007
Views 43,634
Downloads 349
Bookmarked 25 times

Hiding the Caption and Icon in the Title Bar in Windows Vista

By | 28 Apr 2007 | Article
Prevent the Caption and Icon from appearing in the Title Bar, while still appearing in the Task bar, like Windows Explorer

Screenshot - hide.png

Introduction

Ever noticed in Windows Explorer (My Computer) that the Caption (Title Bar Text) and Icon are not displayed? Ever wondered how to do it in your program?
This Guide Will Show You How.

Background

Say you have extended the Glass Effects a bit further (like in the example) and then have put a larger, easier to read title there, or perhaps a logo instead. Or as in Explorer you have what is usually in the title available just a bit further down. For example, this is the same as the screenshot above, but with the Caption visible:

Screenshot - nohide.png

It seems kind of pointless doesn't it? You may go as far to say it looks very unprofessional. Well, Vista has functions that enable you to hide the Caption and Icon, the best thing about using these is that the caption still appears in the task bar at the bottom. If you tried to remove it by blanking out the .Text property, the caption would disappear in the task bar, which will lead to confusion.

Using the code

Unfortunately there is no way to set the properties we want in Managed code, so we have to call Native "Unmanaged" Code to hide it. Luckily its not too hard to move over and it works perfectly. To Use it, you must first fill in an WTA_OPTIONS struct, which contains what you want to remove, and then you must call the function.

DWM.WTA_OPTIONS ops = new DWM.WTA_OPTIONS();
// We Want To Hide the Caption and the Icon
ops.Flags = DWM.WTNCA_NODRAWCAPTION | DWM.WTNCA_NODRAWICON;
// If we set the Mask to the same value as the Flags, the Flags are Added. 
// If not they are Removed
ops.Mask = DWM.WTNCA_NODRAWCAPTION | DWM.WTNCA_NODRAWICON;
// Set It, The Marshal.Sizeof() stuff is to get the right size of the 
// custom struct, and in UINT/DWORD Form
DWM.SetWindowThemeAttribute(this.Handle,
    DWM.WindowThemeAttributeType.WTA_NONCLIENT,
        ref ops,
        (uint)Marshal.SizeOf(typeof(DWM.WTA_OPTIONS)
); 

I provided in the Code all four Flags that Microsoft documented, although you will probably only use the first two. If you don't understand the line:

(uint)Marshal.SizeOf(typeof(DWM.WTA_OPTIONS) 

Don't Worry, its just to get the right memory size for the Structure. You will never need to change it even if you change the flags.

Points of Interest

Writing this code helped me realise just how easy it was to use native code in C#. Finding out the function to use took a lot longer than writing it!

The uints everywhere are C# closest match to DWORD, which is what the documentation specifies as the top.

For some reason, Microsoft made the AttributeType an enum, although at the moment there is only one value, WTA_NONCLIENT or 1. I kept it as an enum for consistency with the native code.

In the download, I also included the DWM Code to extend margins, because it works well with this, and is not that hard to do. I didn't write it, but I saw it on numerous sites so I can't remember who to credit. Sorry!

History

  • 1.0 - First Revision

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nic Hubbard

Student

United Kingdom United Kingdom

Member

Astrophysics student with an enjoyment of programming.
Currently experimenting with emulation in C++, and
experimenting with assembly (ARM and x86)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionThe download source and binaries link is broken PinmemberDominic He21:44 3 May '12  
Generalinterestingly this still leaves the icon's context menu enabled PinmemberPatrick Klug18:12 14 Mar '10  
GeneralGreat Pinmemberpimb223:32 24 Jul '09  
QuestionNeat, but how about hiding title bar altogether? Pinmemberlogan133714:56 21 Nov '07  
AnswerRe: Neat, but how about hiding title bar altogether? Pinmemberlogan133716:38 21 Nov '07  
QuestionWhat about WPF PinmemberSveFro5:04 29 Jul '07  
AnswerRe: What about WPF Pinmemberapoll08:55 22 Nov '09  
GeneralThank you - this is what I am looking for Pinmembera-chih8:27 14 Jun '07  
GeneralI prefer to enable them back in the explorer Pinmemberdavepermen4:59 28 Apr '07  
GeneralRe: I prefer to enable them back in the explorer PinmemberNic Hubbard5:55 28 Apr '07  
GeneralRe: I prefer to enable them back in the explorer Pinmemberdavepermen6:05 28 Apr '07  
GeneralRe: I prefer to enable them back in the explorer PinmemberNic Hubbard8:50 28 Apr '07  
GeneralRe: I prefer to enable them back in the explorer Pinmemberrobertw01910:06 28 Apr '07  

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 28 Apr 2007
Article Copyright 2007 by Nic Hubbard
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid