Click here to Skip to main content
Click here to Skip to main content

Full Screen Caption bar

By , 3 Feb 2004
Rate this:
Please Sign up or sign in to vote.

Sample Image - FullScreenHeader.gif

Introduction

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! Smile | :)

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:

//Header
CTitleBar *TitleBar;

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

//Eg on OnCancel()
delete TitleBar;

You can also declare it without pointers:

//Header
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) )
    {
        DispatchMessage(&msg);
    }

    //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

Customizing

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 
//Topmargin
#define tbTopSpace        3 
//Leftmargin
#define tbLeftSpace        20 
//Rightmargin
#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
//tbStartColor=tbEndColor

//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 Smile | :)

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.

History

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

License

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

About the Author

Lars [Large] Werner
Engineer
Norway Norway
I'm looking for new opportunities in Norway, contact me on email, twitter or Facebook
Not able to travel (a lot) so either home office or in Telemark area, Norway.
 
----------------------------------
Visit http://lars.werner.no/ for my techno-blog!
----------------------------------
 
Projects
* Adito - Simple Windows installer for Adito/OpenVPN ALS!
* Unpacker - Auto extract of multiple archives (RAR/ZIP) with queue support and cleanup options!
* SizeMe - Ultimate tool for maximize your output on CD/DVDs!
Follow on   Twitter   Google+

Comments and Discussions

 
GeneralOT PinmemberJörgen Sigvardsson29-Oct-04 11:22 
GeneralRe: OT PinmemberLars [Large] Werner31-Oct-04 1:14 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 4 Feb 2004
Article Copyright 2004 by Lars [Large] Werner
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid