Drawing an active-looking caption even when not active


“Why would somebody ever want to do that?” you might ask. Well, this is a common appearance for floating toolbars. (But aside from that case, I can’t think of any other valid reason to draw a window as active even though it isn’t.)

Fortunately this is easy to do. Just add this line to the WndProc of our scratch program:

    case WM_NCACTIVATE: if (wParam == FALSE) wParam = TRUE; break;

This says, “If Windows asks me to paint my caption bar in the inactive state, turn around and draw it in the active state.”

Comments (20)
  1. Anonymous says:

    Excellent. I don’t suppose you’d want to give a hint on iTunes style caption bars? I kinda like the centered title, and the custom control box (close, min etc) :)

  2. Centaur says:

    Is it moral to want to draw nonstandard captions?

  3. Anonymous says:

    I don’t know where morality comes into it but I think I understand the question.

    Why has no-one complained about Winamp having different skins and by default having a different caption bar? Answer: No-one cares.

    Do MS still even have a HIG?

  4. KiwiBlue says:

    Another reason: if you want to create combobox-like control, which displays popup window. To avoid your mainframe caption getting inactive appearance, you handle WM_NCACTIVATE.

  5. Jacob (.NET MVP) says:

    With WindowsForms in .NET, I have had situations in which I needed a UI that resembles MDI, but is different enough such that the built-in MDI doesn’t do the trick. As an alternative, each form can be treated as a control and be hosted in a container (e.g. a panel). The downside, though, is that the caption bars are always drawn inactive. Of course, these embedded forms never receive WM_NCACTIVATE, so I have to create the message and send it to the DefWndProc of the window. The moral of the story is, "here is another scenario in which the built in management of inactive versus active caption bars is inadequate."

  6. Raymond Chen says:

    Actually in the combobox-like popup control, handling WM_NCACTIVATE is the wrong thing. I’ll write an entry on doing menulike popup windows the right way someday.

  7. Anonymous says:

    "Why has no-one complained about Winamp having different skins and by default having a different caption bar? Answer: No-one cares."

    Think the real answer is that people use winamp in a very different way when compared to the other applications they use. Winamp is commonly kept on top of an active window playing in the background and as such should seek to conserve space. This makes it different UI acceptable. Changing the caption bar (or any gui element) without a very good reason is almost always a mistake, and expecially so if your app is used in a standard way.

  8. Mike Dimmick says:

    Draw your own caption bar by handling WM_NCPAINT. You can handle WM_NCHITTEST if you place your custom buttons in a different location to the standard one.

    MS Office 95 had custom caption bars – the ‘Microsoft’ in the caption used the proper logo and it had a gradient fill. I suspect that it didn’t play well with large fonts and the user’s chosen colour scheme.

  9. phaeron says:

    WinAmp is an example of custom UI done right. In fact, I wish more media players would follow WinAmp’s example, because most are horrible, particularly in terms of screen real estate waste. Windows Media Player, QuickTime, RealPlayer, WinDVD, you name it — all have custom UI that is of dubious or even negative usefulness, usually wasting space for no reason with large, rounded bevels and cute but hard-to-use controls. I still use Windows Media Player 6.4 because its UI consists of: a box, a slider, and a nice, big video pane.

    Custom UI in itself isn’t bad, it’s just that the vast majority of it is done in a way that is less intuitive, less usable, less accessible, and less efficient than the stock Win32 UI controls.

  10. Ross says:

    Maybe a stupid question, but what does the NC stand for in WM_NCHITTEST and WM_NCPAINT ?

  11. John Topley says:

    NC stands for Non-Client. It means the title bar (caption) area of the window.

  12. KiwiBlue says:

    Well, non-client is not only the caption. If you look at the docs form WM_NCHITTEST, you’ll see that NC includes menu, window border and scrollbars added by WS_xSCROLL style.

    Basically, the client area is the one you paint yourself in WM_PAINT. Other things within window rect are considered non-client.

  13. Alex says:

    2 phaeron

    I totally agree with you. Nowadays skins are the most heavily abused thing in Windows. That’s why I keep Classic skin for WMP9 inmy backups. Unfortunately it’s not included in WMP9 installation anymore.

    Die stupid skins, die!

  14. Anonymous says:

    Giant rounded corners almost never help with usability. Pointless eye-candy with no added GUI benifit is quite annoying. The old Windows look is really quite good. Combining the old classic style with mouse-over activiation graphics would really bring it up to date however with regards to tabs, buttons, scrollbars etc…

  15. Shane King says:

    "Why has no-one complained about Winamp having different skins and by default having a different caption bar?"

    I’m a no-one now apparently. :(

    I hate all skinned apps. Including WinAmp. If someone made a player exactly like WinAmp, but without the skins, I’d switch to it immediately.

    As Jamie Zawinski says at http://www.jwz.org/doc/linuxvideo.html

    "Makali wrote:

      Whenever a programmer thinks, "Hey, skins, what a cool idea", their computer's speakers should create some sort of cock-shaped soundwave and plunge it repeatedly through their skulls. 
    

    I am fully in support of this proposed audio-cock technology. "

  16. Timwi says:

    Here’s a somewhat unrelated question, Raymond, and it’d be nice if you’d write a new entry about it. I’m wondering why, in Windows 95, you chose to left-align the title bar captions. They were centered in Windows 3.1x. I remember that I quite liked it that way, and that I was disappointed when Windows 95 left-aligned them. Of course, I’m used to it by now, but I’d really like to know why this change was made.

  17. Anonymous says:

    Im not sure why it was done in Windows95, but the problem with centered text is that it is inconsistent. When the text is left aligned, you always know where it is, as it is fixed. With centered text, that text can move based on the size of the window, and the start of the text line changes when the caption message changes.

    Imagine if the task-bar was center aligned (as the poorly designed mac dock is): there would be no consistancy in the location of the windows. If the task-bar was set to auto-hide, this could become very annoying.

  18. Mat says:

    With a bit of tweaking the window captions can be put back in the middle where they belong. :)

    One thing that puzzles me with the XP GUI is that (if you use anything other than Win Classic as your theme) when a button gets a bit on the wide side the ends get scaled and it looks absolutely hideous. (This mostly happens with forms in IE — it occasionally happens in apps, but it’s not consistent. Some apps are OK, others aren’t…)

  19. Raymond,

    I know that you do not want any comments a few weeks after an entry, but I thought you should be aware that the single line you provide is not sufficient. For example, cover a portion of the program’s caption with another window, and then uncover it. You will find that the redrawn portion will still look inactive.

    I hope that addressing this problem was not intentionally left out due to being out of the article’s scope. If so, I apologize.

Comments are closed.