Home > Windows API > Manually drawing a window’s caption bar

Manually drawing a window’s caption bar

Ever thought of drawing a window’s caption by using an API call. You might have a custom window and you would like to draw it’s caption like window’s would do!

So for this purpose use DrawCaption.

BOOL DrawCaption( HWND hwnd,    // handle to window
                  HDC hdc,      // handle to device context
                  LPCRECT lprc, // rectangle to draw into
                  UINT uFlags   // drawing options );

Following flags specifies how the caption bar is to be drawn. This is real cool, we can really draw a real caption. 😉

DC_ACTIVE The function uses the colors that denote an active caption.
DC_BUTTONS Windows XP: If set, the function draws the buttons in the caption bar (to minimize, restore, or close an application).
DC_GRADIENT Windows 98/Me, Windows 2000/XP: When this flag is set, the function uses COLOR_GRADIENTACTIVECAPTION (if the DC_ACTIVE flag was set) or COLOR_GRADIENTINACTIVECAPTION for the title-bar color.If this flag is not set, the function uses COLOR_ACTIVECAPTION or COLOR_INACTIVECAPTION for both colors.
DC_ICON The function draws the icon when drawing the caption text.
DC_INBUTTON The function draws the caption as a button.
DC_SMALLCAP The function draws a small caption, using the current small caption font.
DC_TEXT The function draws the caption text when drawing the caption.

This is just a copy paste from MSDN. Take a look at DC_BUTTONS, DC_ICON, DC_TEXT, DC_ACTIVE, DC_GRADIENT flags. You should be now knowing how to draw inactive caption bars, caption bars with buttons, gradient caption, caption with text etc.

Drawing caption using themes requires a different approach. We’ve got to use DrawThemeBackground API. Part ids for e.g. can be WP_CAPTION etc. If there is a better way tell me. 🙂

  1. June 13, 2008 at 5:04 am

    Thanks John and good question!

    For themed drawing we can use DrawThemeBackground. Take a look in MSDN for different part ids.

    Links to DrawThemeBackground and different parts…


  2. John Schroedl
    June 12, 2008 at 10:51 pm

    This is nice, thanks for posting. But…what would be even nicer would be a posting on how to do this using theme drawing since DrawCaption doesn’t seem to do that.


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: