Virtual Developer Workshop: Containerized Development with Docker

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)


Download demo project - 17 Kb


  • What I need completely for making a software

    Posted by FzRahmani on 12/17/2012 09:40am

    when I execute an cpp file and open it that shown as cmd document and close automatically and I need some code about delete a directory files in c++ when I execute it and open it not work I want to change it background an title bar and what files I need for making a complete software I saw a software resource files I found .rc files and .dsp and .dsw and other some what work that files for software and how I import that files in cpp file i.e what code I need for import it.

  • WM_NCPAINT in WinCE 5.0 ?

    Posted by asoe72 on 03/06/2008 03:24am

    Thanks for good article. But I can't find WM_NCPAINT in my WinCE 5.0 SDK. Does anyone know how to change titlebar's font at runtime in WinCE 5.0 ?

  • Font of the Dialog titlebar

    Posted by Legacy on 10/13/2003 07:00am

    Originally posted by: Gaurang

    How to change the font of the dilaog's titlebar along with dialog. Also i want to know how to change the default fonts of the messageboxes. Thanks

  • What about the text?

    Posted by Legacy on 09/15/2002 07:00am

    Originally posted by: Tanya Tara

    How do i display the titlebar text? 

  • how to set text for title at runtime ?

    Posted by Legacy on 08/30/2002 07:00am

    Originally posted by: Danny

    I have M1 dialog call to another (C1 dialog).
    Could you tell me how to set text for C1 dialog title at runtime ?

  • displaying icons on title bar

    Posted by Legacy on 12/18/2000 08:00am

    Originally posted by: Srikanth Eswaran


    is there a way to display an icon on the title bar of an application ?

    thanks in advance

  • Icon on taskbar

    Posted by Legacy on 12/20/1999 08:00am

    Originally posted by: Istvan Moldovan

    When the system menu of the dialog box is disabled, the app
    icon will be missing from taskbar. If it is not disabled, a
    click on titlebar will redraw the default close button...
    So, if you want also icon on taskbar, here is a solution:
    - add system menu to the dialog box
    - override WM_NCRBUTTONDOWN with an empty handler to avoid
    redraw on right click and avoid system menu popup (or you
    can set up your own system menu popup)
    - if you don't want to write an own window move function,
    use the following trick in OnNcLButtonDown():
    Instead of:
    This will disable the system menu temporary when moving.

  • Good work, but...

    Posted by Legacy on 12/20/1999 08:00am

    Originally posted by: Joselito Santana

    The close button does not resize when you change the title bar's size in Display->Appearance in the Control Panel. A fix for this would be to recalculate the closeRect.left and closeRect.right coordinates using closeRect.bottom and closeRect.top, respectively:

    // following code is in OnNcPaint in CustomDlg.cpp

    closeRect.top = GetSystemMetrics(SM_CYFRAME) + 1;
    closeRect.bottom = GetSystemMetrics( SM_CYSIZE ) + 1;
    closeRect.left = rc.right - rc.left - closeRect.bottom;
    closeRect.right = rc.right - rc.left - closeRect.top;


    Joselito Santana

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date