Click here to Skip to main content
15,559,121 members
Articles / Desktop Programming / MFC
Posted 3 Feb 2004


121 bookmarked

Full Screen Caption bar

Rate me:
Please Sign up or sign in to vote.
4.65/5 (31 votes)
3 Feb 2004CPOL3 min read
Description on how to implement a full screen caption bar in Win32/MFC.

Sample Image - FullScreenHeader.gif


After working with Remote Desktop from Microsoft, I saw the full screen caption bar that came on top. The FullScreenHeader is a look alike of that caption, it is made in Win32 and I've tried to make it somehow custom. This is my first Win32 app ever released, and there may be errors on it. Please point out any errors done! :-)

Why did I make this? Well, there is this really good open source util called RealVNC. It is a "remote desktop" freeware with very nice clones. Check them out to UltraVNC and TightVNC. Many features have been added and I've already implemented the caption on each of these versions. Hopefully, this gets integrated in future releases of every VNC. If not, you can download all the versions from my website.

Using the code

You need to add five resources to your project. Plus one context menu.

void CTitleBar::LoadPictures()
    hClose=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_CLOSE));
    hMaximize=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MAXIMIZE));
    hMinimize=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_MINIMIZE));
    hPinUp=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PINUP));
    hPinDown=LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PINDOWN));

These pictures are included in the demo project. All pictures should be the same size, but you can decide the width and height. See "customize" for more info.

You also need to add a context menu to the resource, default name is IDR_tbMENU. If you have set the tbLastIsStandard=TRUE then you have to add 3 "default" entries to the menu. From the bottom: Close, Minimize and Restore. All IDs used on each item can be set to e.g.: IDC_NULL since it is not in use. The flag tbWMCOMMANDIDStart/End sets the range for the IDs used in a context menu internally. If you want to add other entries to the context menu, you can add it above the 3 default entries if you're using them. The parent will get a WM_USER+tbWMUSERID+nItem sent to its message queue. (See "Customize" for options that are available to you.)

Implementing in MFC:

CTitleBar *TitleBar;

//Eg in OnInitDialog() procedure
TitleBar=new CTitleBar(AfxGetInstanceHandle(), this->GetSafeHwnd());

//Eg on OnCancel()
delete TitleBar;

You can also declare it without pointers:

CTitleBar TitleBar;

//Eg in OnInitDialog() procedure
Title.Create(AfxGetInstanceHandle(), this->GetSafeHwnd());

Here is a simple Win32 example. It uses the desktop hwnd to create a child toolbar.

#include "stdafx.h"
#include "res\\Resource.h"
#include "FullScreenTitleBar.h"

CTitleBar *TitleBar;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
     // TODO: Place code here.

    TitleBar=new CTitleBar(hInstance, ::GetDesktopWindow());

    MSG msg;

    //Wait until loop is finished
    while ( GetMessage(&msg, NULL, 0,0) )

    //Delete and quit program
    delete TitleBar;

    return 0;

This ends how to implement the caption bar on Win32/MFC. Here are the rest of the public variables:

  • void Create(HINSTANCE hInst, HWND ParentWindow) - Creates a new caption bar
  • void SetText(LPTSTR TextOut) - Sets a header text
  • void DisplayWindow(BOOL Show, BOOL SetHideFlag=FALSE) - DisplayWindow is an alternative to ShowWindow. It adds the "slide" of the window. The option SetTheHideflag is an override so when it is true and window scrolls to top, it will call a ShowWindow(m_hWnd, SW_HIDE)
  • HWND GetSafeHwnd() - Returns the HWND for the main window


There are several options that might be changed in compile time for the caption bar. Here is a complete list:

//Width of captionbar
#define tbWidth            500 
//Height of captionbar
#define tbHeigth        20 
//Default size on picture (cx)
#define tbcxPicture        16 
//Default size on picture (cy)
#define tbcyPicture        14 
#define tbTopSpace        3 
#define tbLeftSpace        20 
#define tbRightSpace        20
//Space between buttons 
#define tbButtonSpace        1 
//Font name used in the caption
#define tbFont            "Arial" 
//Size of font
#define tbFontSize        10 
//Color of text
#define tbTextColor        RGB(255,255,255) 
//Backgroundcolor - Start of gradient
#define tbStartColor        RGB(0,128,192) 
//Backgroundcolor - End of gradient
#define tbEndColor        RGB(0,0,192) 

#define tbGradientWay        TRUE
//TRUE = Vertical, FALSE = Horiz. If you don't like gradient set

//Color of the border around captionbar
#define tbBorderPenColor    RGB(255,255,255) 
//Color of the shadow of the captionbar (bottom)
#define tbBorderPenShadow    RGB(100,100,100) 
#define tbTriangularPoint    10 
//Triangularpoint is how many pixel if should move on the left and right
//side to make the captionbar not so like the other captionbars

//Width of the pen used to draw the border
#define tbBorderWidth        2 
//Hide window when created
#define tbHideAtStartup        TRUE 
//Is the pin pushed in or out at startup (INVERTED!)
#define tbPinNotPushedIn    FALSE
//Animate window to scroll up/down 
#define tbScrollWindow        TRUE
//Timer variable for scrolling the window (cycletime) [ms] 
#define tbScrollDelay        20
#define tbAutoScrollTime    10
//* tbAutoScrollDelay milliseconds steps. Meaning if it is 10 then
//= 10 (steps) * 100ms (tbAutoScrollDelay) = 1000ms delay

//Timer id - Internally used but it can make conflicks!
#define tbScrollTimerID        1
//Timer id - Internally used but it can make conflicks!
#define tbAutoScrollTimer    2
#define tbAutoScrollDelay    100 
//Timer variable for how many times the cursor is not over the window.
//If it is tbAutoScrollTime then it will hide if autohide

//Resource ID - closebutton
#define tbIDC_CLOSE        10 
//Resource ID - maximizebutton
#define tbIDC_MAXIMIZE        20 
//Resource ID - minimizebutton
#define tbIDC_MINIMIZE        30 
//Resource ID - pinbutton
#define tbIDC_PIN        40 
#define tbDefault        FALSE 
//FALSE = Send a custon WM message, TRUE = Send Minimize, maximize
//and close to parent (normal Sendmessage and Showmessage commands)

//Message to send to parent on close-event
#define tbWM_CLOSE        WM_USER+1000 
//Message to send to parent on minimize-event
#define tbWM_MINIMIZE        WM_USER+1001 
//Message to send to parent on maximize-event
#define tbWM_MAXIMIZE        WM_USER+1002 
//Resource name for the contextmenu
#define tbMENUID        IDR_tbMENU 
#define tbWMCOMMANDIDStart    50000 
//Start: This is the internal id number sendt 
//into the WM_COMMAND on each item

#define tbWMCOMMANDIDEnd    51000 
//End: This is the internal id number sendt 
//into the WM_COMMAND on each item
#define tbWMUSERID        2000 
//This is WM_USER+n setting. Eg: if first item is clicked you will
//get an WM_USER+n+0 to the parent, and WM_USER+n+1 for the next item
#define tbLastIsStandard    TRUE 
//TRUE = Bottom of the menu is close, minimize and restore, 
//FALSE = Every item is sendt as WM_USER+n to parent

All other variables (private) should not be tweaked, it may cause failure in other procedures in the program. Modify on own risk :)

Known issues

Sometimes when you delete the caption bar, a destroywindow is called. Since the window is made as a child, it will send a message to the parent asking to close. This might cause the parent to close also. A solution to this problem is to create the caption bar on runtime, hide it and show it as you need it. And when the main program closes, you can destroy the object.

This bug will be sorted out in a later version.

If you encounter that no messages are being sent to your parent window, please check the tbDefault variable. If the user presses the contextmenu, it will send a "click" to any of the buttons in the parent, and use the parameters used at the buttons.


  • First release (non public): V1.0
  • First release: v1.1


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Engineer A/S Norske Shell (Dutch Shell)
Norway Norway
Visit for my blog!
Retired programmer, Norway never had the jobs I wanted Smile | :)

Comments and Discussions

GeneralMouse Up Pin
bling24-Jun-10 12:39
bling24-Jun-10 12:39 
GeneralThe FullScreenTitleBar does not work with CDialog. Pin
IVarshilov2-Sep-09 11:56
IVarshilov2-Sep-09 11:56 
GeneralPretty good! Pin
wshcdr18-Aug-09 19:32
wshcdr18-Aug-09 19:32 
GeneralAlt-Tab Switch is broken during fullscreen Pin
Fred W24-Aug-05 2:55
Fred W24-Aug-05 2:55 
GeneralRe: Alt-Tab Switch is broken during fullscreen Pin
Lars [Large] Werner24-Aug-05 4:13
professionalLars [Large] Werner24-Aug-05 4:13 
GeneralRe: Alt-Tab Switch is broken during fullscreen Pin
Fred W24-Aug-05 12:49
Fred W24-Aug-05 12:49 
GeneralRe: Alt-Tab Switch is broken during fullscreen Pin
Lars [Large] Werner25-Aug-05 5:24
professionalLars [Large] Werner25-Aug-05 5:24 
GeneralOT Pin
Jörgen Sigvardsson29-Oct-04 12:22
Jörgen Sigvardsson29-Oct-04 12:22 
GeneralRe: OT Pin
Lars [Large] Werner31-Oct-04 2:14
professionalLars [Large] Werner31-Oct-04 2:14 
GeneralExcellet Work Pin
Koundinya10-Mar-04 20:55
Koundinya10-Mar-04 20:55 
GeneralFinally - a feature VNC viewer was missing Pin
Hans J. Schroeder6-Mar-04 11:23
Hans J. Schroeder6-Mar-04 11:23 
GeneralRe: Finally - a feature VNC viewer was missing Pin
Lars [Large] Werner6-Mar-04 13:15
professionalLars [Large] Werner6-Mar-04 13:15 
GeneralWrap! Pin
Shog94-Feb-04 14:10
sitebuilderShog94-Feb-04 14:10 
GeneralRe: Wrap! Pin
Lars [Large] Werner4-Feb-04 19:47
professionalLars [Large] Werner4-Feb-04 19:47 
GeneralExcellent Pin
PixiGreg4-Feb-04 12:10
PixiGreg4-Feb-04 12:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.