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! :-)
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;
TitleBar=new CTitleBar(AfxGetInstanceHandle(), this->GetSafeHwnd());
delete TitleBar;
You can also declare it without pointers:
CTitleBar TitleBar;
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)
{
TitleBar=new CTitleBar(hInstance, ::GetDesktopWindow());
MSG msg;
while ( GetMessage(&msg, NULL, 0,0) )
{
DispatchMessage(&msg);
}
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:
#define tbWidth 500
#define tbHeigth 20
#define tbcxPicture 16
#define tbcyPicture 14
#define tbTopSpace 3
#define tbLeftSpace 20
#define tbRightSpace 20
#define tbButtonSpace 1
#define tbFont "Arial"
#define tbFontSize 10
#define tbTextColor RGB(255,255,255)
#define tbStartColor RGB(0,128,192)
#define tbEndColor RGB(0,0,192)
#define tbGradientWay TRUE
#define tbBorderPenColor RGB(255,255,255)
#define tbBorderPenShadow RGB(100,100,100)
#define tbTriangularPoint 10
#define tbBorderWidth 2
#define tbHideAtStartup TRUE
#define tbPinNotPushedIn FALSE
#define tbScrollWindow TRUE
#define tbScrollDelay 20
#define tbAutoScrollTime 10
#define tbScrollTimerID 1
#define tbAutoScrollTimer 2
#define tbAutoScrollDelay 100
#define tbIDC_CLOSE 10
#define tbIDC_MAXIMIZE 20
#define tbIDC_MINIMIZE 30
#define tbIDC_PIN 40
#define tbDefault FALSE
#define tbWM_CLOSE WM_USER+1000
#define tbWM_MINIMIZE WM_USER+1001
#define tbWM_MAXIMIZE WM_USER+1002
#define tbMENUID IDR_tbMENU
#define tbWMCOMMANDIDStart 50000
#define tbWMCOMMANDIDEnd 51000
#define tbWMUSERID 2000
#define tbLastIsStandard TRUE
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.
History
- First release (non public): V1.0
- First release: v1.1