Click here to Skip to main content
15,879,326 members
Articles / Programming Languages / C#
Article

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

Rate me:
Please Sign up or sign in to vote.
4.15/5 (14 votes)
28 Apr 20072 min read 84.2K   1.2K   29   14
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.

C#
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:

C#
(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


Written By
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? Pin
Muhammad Haris from Wah Cantt14-Jul-12 23:16
Muhammad Haris from Wah Cantt14-Jul-12 23:16 
QuestionThe download source and binaries link is broken Pin
Dominic He3-May-12 21:44
Dominic He3-May-12 21:44 
Generalinterestingly this still leaves the icon's context menu enabled Pin
Patrick Klug14-Mar-10 18:12
Patrick Klug14-Mar-10 18:12 
Got my 5
Interestingly, while it removes the icon it still leaves the context menu (which you can see when you left click in the top left of the window) enabled. Would be nice to deactivate this as well. I am currently looking for a way to do that and thus stumbled on your article...
GeneralGreat Pin
pimb224-Jul-09 23:32
pimb224-Jul-09 23:32 
QuestionNeat, but how about hiding title bar altogether? Pin
chaiguy133721-Nov-07 14:56
chaiguy133721-Nov-07 14:56 
AnswerRe: Neat, but how about hiding title bar altogether? Pin
chaiguy133721-Nov-07 16:38
chaiguy133721-Nov-07 16:38 
QuestionWhat about WPF Pin
SveFro29-Jul-07 5:04
SveFro29-Jul-07 5:04 
AnswerRe: What about WPF Pin
apoll022-Nov-09 8:55
apoll022-Nov-09 8:55 
GeneralThank you - this is what I am looking for Pin
aChih14-Jun-07 8:27
aChih14-Jun-07 8:27 
GeneralI prefer to enable them back in the explorer Pin
davepermen28-Apr-07 4:59
davepermen28-Apr-07 4:59 
GeneralRe: I prefer to enable them back in the explorer Pin
Nic Hubbard28-Apr-07 5:55
Nic Hubbard28-Apr-07 5:55 
GeneralRe: I prefer to enable them back in the explorer Pin
davepermen28-Apr-07 6:05
davepermen28-Apr-07 6:05 
GeneralRe: I prefer to enable them back in the explorer Pin
Nic Hubbard28-Apr-07 8:50
Nic Hubbard28-Apr-07 8:50 
GeneralRe: I prefer to enable them back in the explorer Pin
robertw01928-Apr-07 10:06
robertw01928-Apr-07 10:06 

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

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