Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

Fullscreen caption bar

A full screen caption bar for applications that is running full screen and need to have some extra features. This is the same caption bar used on the VNC clones.

Check it out on:
Codeproject.com
Codeguru.com
Planetsourcecode.com

Fullscreen caption bar

FullScreenHeader.zip 74.77 kB
FullScreenHeaderSrc.zip (7.52 kB)

Fullscreen captionbar

Environment: VC6 SP5, NT4 SP3, Win9x, Win2k and WinXP

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 every released, and it may be errors on it. Please point out any errors done! 🙂

Why did I made this? Well it is the really good opensource util called
RealVNC (http://www.realvnc.com). It is a
"remote desktop" freeware with very nice clones. Check them out to
UltraVNC (http://www.ultravnc.com) and
TightVNC (http://www.tightvnc.com). Many
features added and I’ve already implemented the caption on each of these
versions. Hopefully this get integrated in feature releases of every VNC. If not
you can download all the versions from my website: http://lars.werner.no

Using the code

You need to add five resources to you’re 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 demoproject. All pictures should be the same size, but you decide the width and height. See “customize” for more info.

You also need to add an 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, Minmize and
Restore. All IDs used on each item can be set to eg: IDC_NULL since it is not in
use. The flag tbWMCOMMANDIDStart/End set 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 an
WM_USER+tbWMUSERID+nItem sendt to its messagequeue. (Se "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,
intnCmdShow)

{
// 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 captionbar on Win32/MFC. Here are the rest of the public variables:
void Create(HINSTANCE hInst, HWND ParentWindow) – Create a new caption bar
void SetText(LPTSTR TextOut) – Set a headertext
void DisplayWindow(BOOL Show, BOOL SetHideFlag=FALSE) – Displaywindow is an alternative to showwindow. It adds the “slide” of the window. The option “SetTheHideflag” is a override so when it is true and window scroll 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 change in compiletime for the captionbar. Her is a complete list:
#define tbWidth 500 //Width of captionbar
#define tbHeigth 20 //Height of captionbar
#define tbcxPicture 16 //Default size on picture (cx)
#define tbcyPicture 14 //Default size on picture (cy)
#define tbTopSpace 3 //Topmargin
#define tbLeftSpace 20 //Leftmargin
#define tbRightSpace 20 //Rightmargin
#define tbButtonSpace 1 //Space between buttons
#define tbFont "Arial" //Font name used in the caption
#define tbFontSize 10 //Size of font
#define tbTextColor RGB(255,255,255) //Color of text
#define tbStartColor RGB(0,128,192) //Backgroundcolor - Start of gradient
#define tbEndColor RGB(0,0,192) //Backgroundcolor - End of gradient
#define tbGradientWay TRUE //TRUE = Vertical, FALSE = Horiz. If you don't like gradient set tbStartColor=tbEndColor
#define tbBorderPenColor RGB(255,255,255) //Color of the border around captionbar
#define tbBorderPenShadow RGB(100,100,100) //Color of the shadow of the captionbar (bottom)
#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
#define tbBorderWidth 2 //Width of the pen used to draw the border
#define tbHideAtStartup TRUE //Hide window when created
#define tbPinNotPushedIn FALSE //Is the pin pushed in or out at startup (INVERTED!)
#define tbScrollWindow TRUE //Animate window to scroll up/down
#define tbScrollDelay 20 //Timer variable for scrolling the window (cycletime) [ms]
#define tbAutoScrollTime 10 //* tbAutoScrollDelay milliseconds steps. Meaning if it is 10 then = 10 (steps) * 100ms (tbAutoScrollDelay) = 1000ms delay
#define tbScrollTimerID 1 //Timer id - Internally used but it can make conflicks!
#define tbAutoScrollTimer 2 //Timer id - Internally used but it can make conflicks!
#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
#define tbIDC_CLOSE 10 //Resource ID - closebutton
#define tbIDC_MAXIMIZE 20 //Resource ID - maximizebutton
#define tbIDC_MINIMIZE 30 //Resource ID - minimizebutton
#define tbIDC_PIN 40 //Resource ID - pinbutton
#define tbDefault FALSE //FALSE = Send a custon WM message, TRUE = Send Minimize, maximize and close to parent (normal Sendmessage and Showmessage commands)
#define tbWM_CLOSE WM_USER+1000 //Message to send to parent on close-event
#define tbWM_MINIMIZE WM_USER+1001 //Message to send to parent on minimize-event
#define tbWM_MAXIMIZE WM_USER+1002 //Message to send to parent on maximize-event
#define tbMENUID IDR_tbMENU //Resource name for the contextmenu #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 ect ect (sendt to parent) #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.

An 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 close, you can destroy the object.
This bug will be sorted out in an later version.

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