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

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

, 28 Apr 2007
Rate this:
Please Sign up or sign in to vote.
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
Astrophysics student with an enjoyment of programming.
Currently experimenting with emulation in C++, and
experimenting with assembly (ARM and x86)

Comments and Discussions

 
QuestionHow do I hide the caption and icon in VB.NET? PinmemberMember 867663814-Jul-12 23:16 
QuestionThe download source and binaries link is broken PinmemberDominic He3-May-12 21:44 
Generalinterestingly this still leaves the icon's context menu enabled PinmemberPatrick Klug14-Mar-10 18:12 
GeneralGreat Pinmemberpimb224-Jul-09 23:32 
QuestionNeat, but how about hiding title bar altogether? Pinmemberlogan133721-Nov-07 14:56 
AnswerRe: Neat, but how about hiding title bar altogether? Pinmemberlogan133721-Nov-07 16:38 
QuestionWhat about WPF PinmemberSveFro29-Jul-07 5:04 
AnswerRe: What about WPF Pinmemberapoll022-Nov-09 8:55 
GeneralThank you - this is what I am looking for Pinmembera-chih14-Jun-07 8:27 
GeneralI prefer to enable them back in the explorer Pinmemberdavepermen28-Apr-07 4:59 
GeneralRe: I prefer to enable them back in the explorer PinmemberNic Hubbard28-Apr-07 5:55 
GeneralRe: I prefer to enable them back in the explorer Pinmemberdavepermen28-Apr-07 6:05 
GeneralRe: I prefer to enable them back in the explorer PinmemberNic Hubbard28-Apr-07 8:50 
GeneralRe: I prefer to enable them back in the explorer Pinmemberrobertw01928-Apr-07 10:06 

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 | Mobile
Web03 | 2.8.140721.1 | Last Updated 28 Apr 2007
Article Copyright 2007 by Nic Hubbard
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid