Welcome to MSDN Blogs Sign in | Join | Help

If you ask for a window caption, you also get a border

Some people may have noticed that the WS_CAPTION is defined as the combination of WS_BORDER and WS_DLGFRAME:

#define WS_CAPTION          0x00C00000L     /* WS_BORDER | WS_DLGFRAME  */
#define WS_BORDER           0x00800000L
#define WS_DLGFRAME         0x00400000L

Since WS_CAPTION includes WS_BORDER, it is impossible to get a caption without a border.

Sometimes people don't quite get this and keep asking the question over and over again, and I have to keep trying to explain the laws of logic in different ways until one of them finally sinks in.

"I noticed that if I set the WS_CAPTION style, I get a window with a title bar and a border. I don't want the border. How do I get rid of the border? I tried all sorts of combinations of window styles but none of them get me what I want."

"If you look at the definition, WS_CAPTION includes WS_BORDER, so you can't get a caption without a border."

"But I see other controls that don't have a border. Static controls on a dialog box, for example, don't have a border, so obviously it's possible to remove the border. How do I do that?"

"They don't have borders, but then again, they don't have captions either. Caption implies border."

"But I want a window with a caption and no border. What window styles do I need to use to get that? Do I have to implement it some other way?"

"Caption implies border. Contrapositive: No border implies no caption. If you don't like that, you'll have to take it up with Russell and Whitehead."

Of course, you can just choose to leave the system entirely and use none of the styles at all and just paint a custom caption. What you get isn't a real caption, though with enough work you can make it look and act like one. Or at least, make it look and act like one up to the present time. If you have the power of clairvoyance, you might be able to make it look and act like a caption in future versions of the operating system, but I suspect your psychic powers are not quite powerful enough to pull that off.

Published Thursday, March 09, 2006 7:00 AM by oldnewthing
Filed under:

Comments

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 10:15 AM by Moi
"and just paint a custom caption"

I actually had to do this once. A horrendous amount of work, for, as far as I am concerned, very little return. I'm not sure who I hate more - whoever decided that "if you ask for a caption you must have a border" or the woever made that requirement for the application I was writing.

It does bring up the question though - why is this so?

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 10:34 AM by ringzero
Once again, some developers are confused by another retarded design decision by Microsoft, and Mr. Chen blames the victim.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 10:41 AM by Gabe
Would somebody care to enlighten me as to what a window would look like if it had a title bar but no border?

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 11:04 AM by Matthew
A little like this, I'd imagine:
<a href="http://img79.imageshack.us/my.php?image=noborder7mj.png">Window with no border</a>

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 11:43 AM by Starfish
A maximised window has no border (that you can see, anyway!)
Fixed link:
http://img79.imageshack.us/my.php?image=noborder7mj.png

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 12:20 PM by oldnewthing
ringzero: Nowhere did I argue that the design was a good one. But even if you don't like something, you still have to obey the rules of boolean logic.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 12:27 PM by Threetwosevensixseven
It's because: if you don't have a border, the edges will fray.

# How bad is it?

Thursday, March 09, 2006 12:35 PM by James Risto
While I certainly understand the frustration when the thing one is working with does not do EXACTLY what I want it to, if the fallback is not so bad, then where's the beef? So you get a border ... at least it does not mean its a sizeable window. Hey - your competitor's windows have borders too!

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 12:36 PM by L7
What I cannot get is why there is no DrawCaptionBar (and the needed GetCaptionBarSize, etc) or similar API to aid the developer who needs to draw a custom caption bar.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 12:59 PM by Click here for DrawCaption action.
Oh, you mean DrawCaption()?  

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 1:02 PM by kokorozashi
Seems to me that the repeated occurrence of this conversation suggests the need for an additional API of some sort.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 1:04 PM by kokorozashi
D'oh! That will teach me to comment without refreshing. Maybe.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 1:31 PM by Randolpho
<i>Oh, you mean DrawCaption()?</i>

There you go, Raymond. The next time somebody says "I want a window with a caption, but no border", you tell them to use a frame and DrawCaption().

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 3:50 PM by Drew Cooper
Arguably, this indicates a usability problem. As does a large subset of the "psychic debugging". I'm not pointing any fingers; I'm guilty of that myself. In my heart of hearts I don't believe that we'll ever fix those bugs. It's not sexy work and it doesn't drive revenue.

But what do I know? I'm just some schmuck tester.

- Drew

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 5:45 PM by ATZ Man
Style flags and condensed MFC description edited by me:
WS_DLGFRAME: The frame that dialog boxes get, which by recent convention is thick and possibly beveled. No caption though.
WS_BORDER: a border.
WS_CAPTION: a caption. But 'implies' WS_BORDER.

It's hard to help explain this with the bit values, because WS_DLGFRAME is a border, and so is WS_BORDER, but OR'ing two borders gives you a caption. Russell and Whitehead surely are not taking sides here. But really you should be describing it as an enum field in the middle of the style word. Four options, none of which are what the particular user wants, because someone back in the mists of time exercised some discretion.

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 7:30 PM by Tim
"Or at least, make it look and act like one up to the present time. If you have the power of clairvoyance, you might be able to make it look and act like a caption in future versions of the operating system, but I suspect your psychic powers are not quite powerful enough to pull that off."

Perhaps you'd better tell that to the Office team:

http://blogs.msdn.com/jensenh/archive/2006/03/09/547281.aspx

# re: If you ask for a window caption, you also get a border

Thursday, March 09, 2006 10:43 PM by Vince P
Tim:

Many of us are not wearing our mind-reading hats.  What exactly should be told to Office and why?

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 12:34 AM by josh
Or if you want to get really fancy, you can set the window region to crop off the border...

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 2:26 AM by Chris Becke
@Vince: At a guess, simply the observation that of any App on my grandfathers PC, the one app most likley to deviate from the "normal" is Office.

Ironically its the same reason I despise open source applications on Win32. They *never* use the windows widgets. Simple standard things like menu's and file open dialogs always have to be "improved".

But I can never complain, because while the OOS apps are wasting their time re-inventing a the wheel, the Office team is doing the same damned thing.

Much to the confusion of my grandfather.

Then, even worse, my boss comes to me, particularly enamored with some new office widget and wants it in the app im developing. Can I drop in a standard implementation of the widget from user32 or shell32 or even a standard OCX? NO. The damn thing is hardcoded into office. So I have to (a) re-implement it from scratch, (b) fail to get the behaviour exactly the same anyway, and (c) know that I - unlike the office team - wont have the benefit of being able to re-write it per OS flavor and that its going to look really crap on any newer (or older) OS versions I get run on.

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 4:46 AM by kyrox
>> Ironically its the same reason I despise open source applications on Win32. They *never* use the windows widgets. Simple standard things like menu's and file open dialogs always have to be "improved". But I can never complain, because while the OOS apps are wasting their time re-inventing a the wheel, the Office team is doing the same damned thing.

OOS does this using GTK, Qt or WXWidgets to keep (as much as possible) compatibility of GUI code across all the supported operative systems. BTW most commercial software does this too, just thinking of 3dsmax, photoshop, office, etc.

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 4:49 AM by Moi
"if you don't have a border, the edges will fray"

Okay, thanks for the explanation ;)

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 5:53 AM by 8
IANAL, but the caption bar is PART OF the border. A maximised window actually still has a border! Try maximising a window with fixed width/height, and drag it away from the edge of the screen. You see, there's still a border.

And there are definately useability problems with creating a title bar in a client area. Besides from more obvious problems, you don't know what accessibilty programs a user might have running, and you have no idea how you'll break them.

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 8:59 AM by Nawak
@Chris Becke "Then, even worse, my boss comes to me, particularly enamored with some new office widget and wants it in the app im developing. Can I drop in a standard implementation of the widget from user32 or shell32 or even a standard OCX? NO"

Well... I thought the same but then I saw SmartFTP letting me choose a "drawing manager" for the UI and the list seemed to match what was installed on the PC ('Standard Windows' style , 'Office 2000' style, 'Visual Studio' style etc.). So there has to be a (maybe) 'deeply buried and misdocumented for the competitors'-way to use the UI from Office and other MS tools.

# re: If you ask for a window caption, you also get a border

Friday, March 10, 2006 10:31 AM by Justin
@Nawak: No, these are from 3rd party libraries such as those created by companies like BCGSoft, CodeJock and FOSS Software.

# re: If you ask for a window caption, you also get a border

Saturday, March 11, 2006 12:18 AM by Vorn
8's got it.  Freecell is an app with a fixed maximum width; you can use that to see what's up.

Vorn

# re: If you ask for a window caption, you also get a border

Monday, March 20, 2006 5:37 AM by Neil
So when calling DrawCaption how do you tell if your caption is active or not (not forgetting to take FlashWindow into account, of course)?
New Comments to this post are disabled
 
Page view tracker