Introduction
If you want to give your users some feedback and make your apps look more professional,
than just use these simple classes. This code was inspired by Mustafa Demirhan's article about
hacking the
CPropertySheet.
The CDialogHeader
class will add a header area to your dialogs
that will display an icon, a title, and some description text.
Below is an image of a standard dialog with a header control added.
The header can display an icon, a title, and description text with a custom
font size, alignment, and background color.
The CMyPropertySheet
class incorporates the dialog header into
a property sheet control.
Below are two tabs of a property sheet control with the header control built
in. Each tab can have it's own individual icon and text associated with it.
How to Use the CDialogHeader Class
- Include the files
DialogHeader.h
and DialogHeader.cpp
in your project.
- Add the include statement to your dialog header file:
#include 'DialogHeader.h' //For the header ctrl area
- Add a member variable of type
CDialogHeader
to your dialog classCDialogHeader m_HeaderCtrl;
In your dialogs OnInit
function do the following:
- Set the headers display data:
m_HeaderCtrl.SetHeaderData(hIcon,"Title","Description");
Or you can set/change each member individually using:
m_HeaderCtrl.SetIconHandle(hIcon);
m_HeaderCtrl.SetTitleText("Title");
m_HeaderCtrl.SetDescText("Description.");
- The above functions will be the most commonly used, however you can set all of the following options:
Font sizes
|
m_HeaderCtrl.SetFontSizes(TitleSize,DescSize);
|
Text alignment
|
m_HeaderCtrl.SetTextAlign(DT_LEFT);
|
Background color
|
m_HeaderCtrl.SetBackgroundColor(RGB(255,255,255));
|
Blank icon mode
|
m_HeaderCtrl.SetBlankIcon(TRUE);
allocated for icon
|
Icon offsets
|
m_HeaderCtrl.SetIconOffset(5);
corner of icon and border
|
Title offset
|
m_HeaderCtrl.SetTitleOffset(10);
icon and title text
|
Description offset
|
m_HeaderCtrl.SetDescOffset(10);
amount of indent for desc text when align is DT_LEFT or DT_RIGHT
|
Header height
|
m_HeaderCtrl.SetHeaderHeight(x);
sets height
|
Note: Font sizes and offset must be set before setting header height with x=0. See the header file for a more complete description of all functions.
- Display the header and resize the dialog window by calling:
m_HeaderCtrl.Init(this);
- Move dialog controls down to accommodate the header area by calling:
m_HeaderCtrl.MoveCtrls(this);
That’s it! The code below shows a typical example of how to initialize
and display the dialog header:
BOOL CDlgFileTypes::OnInitDialog()
{
CDialog::OnInitDialog();
m_HeaderCtrl.SetTitleText("Title");
m_HeaderCtrl.SetDescText("Description text.");
m_HeaderCtrl.SetIconHandle(AfxGetApp()->LoadIcon(IDI_HARDDRIVE));
m_HeaderCtrl.Init(this);
m_HeaderCtrl.MoveCtrls(this);
return TRUE;
}
How to Use the MyPropertySheet Class:
- Include the files
DialogHeader.h
, DialogHeader.cpp
,
MyPropertySheet.h
, and MyPropertyShett.cpp
in your project.
- Add the include statement in every header file where you want to replace the standard
CPropertySheet
#include "MyPropertySheet.h" //For the custom Propertysheet ctrl
- Add a new
CMyPropertySheet
member variable/local variable or replace
CPropertySheet
with CMyPropertySheet
.
- Add the property pages to the property sheet using a
PSHEETITEM
variable.
Note: See the header file for a more complete description of all the functions
and options.
The example below creates a property sheet with two tabs each with different
icon, text, and layout:
void CDialogHeaderDemoDlg::OnButton1()
{
CMyPropertySheet sheet("Options");
PropPage1 page1;
CPropPage2 page2;
PSHEETITEM pItem;
pItem=sheet.GetDefaultPSItem;
pItem.sTitle="Title 1";
pItem.sDesc="Propertypage number 1 options.";
pItem.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
sheet.AddPage(&page1,pItem);
pItem.sTitle="Title 2";
pItem.sDesc="Propertypage number 2 options.";
pItem.hIcon=AfxGetApp()->LoadIcon(IDI_HARDDRIVE);
pItem.uAlign=DT_CENTER;
sheet.AddPage(&page2,pItem);
sheet.DoModal();
}
I hope you enjoy the code and find it useful.