March 9th, 2006

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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.