Draw on Title Bar

Many people was asking how to change the title bar of a window. Here is a small sample,
which draws a color gradient on the title bar.

First, we create a simple dialog box without system menu. Then, we have to intercept the
WM_NCPAINT message and set up an own hanler, which draws the title bar of the window.
To draw on the title bar, we must set up a CWindowDC device context, to draw on non-client
area of the window. To draw the system buttons, we use the DrawFrameControl member.

That’s all!! If you don’t want system menu, close or minimize button. But if we want some
of these, you need to set up handlers for mouse events. (WM_NCLBUTTONDOWN, WM_NCHITTEST,
WM_NCLBUTTONUP)

The small sample project draws a gradient title bar for a dialog window, with close button.
(I compiled with VisualC++ 5.0)

Downloads

Download demo project – 17 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read