Click here to Skip to main content
11,493,937 members (60,329 online)
Click here to Skip to main content

CDialogEx, CPropertySheetEx2 classes with status bar, toolbar and tool tips

, 28 Sep 2002 227.6K 4.9K 59
Rate this:
Please Sign up or sign in to vote.
CDialogEx and CPropertySheetEx2 are classes derived from CDialog and CPropertySheetEx with support for status bar, toolbar and tool tips

CDialogEx and CPropertySheetEx2

Motivation

When I saw Nish's article with a status bar in dialog window I finally decided to publish my CDialogEx and CPropertySheetEx2 classes with support for status bar, toolbar and tool tips. I had similar problem a while ago, when I needed to develop simple application, but with not too ugly interface.

It is not complicated task to have a status bar or toolbar at the dialog window. It becomes little bit more tricky, when you want to do it right way - show tool tips and corresponding status bar messages to these tool tips - and that's the reason, why there is usually status bar, isn't it?. Fortunately I found some information in MSND and got it working.

There is sample DLGCBR32 with description how to add control bars to CDialog. My classes are based on this sample and are extended to keep usage of its functionality as simple as possible.

Description of solution

CDialog and CPropertySheet do not contain similar function to CFrameWnd where all the processing of messages related to control bars is done. It is necessary duplicated this functionality for windows not derived from CFrameWnd. However, this task is more difficult, if you want support modal and modeless dialog windows, where not all messages are sent as you might expect.

As you can see from following message map:

BEGIN_MESSAGE_MAP(CDialogEx, CDialog)
	//{{AFX_MSG_MAP(CDialogEx)
	ON_WM_ENTERIDLE()
	ON_MESSAGE(WM_POPMESSAGESTRING, OnPopMessageString)
	ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
	ON_WM_MENUSELECT()     
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_NUM, OnUpdateKeyIndicator)
	ON_UPDATE_COMMAND_UI(ID_VIEW_STATUS_BAR, OnUpdateStatusBarMenu)
	ON_COMMAND(ID_VIEW_STATUS_BAR, OnStatusBarCheck)  
	ON_COMMAND(ID_VIEW_TOOLBAR, OnToolBarCheck)
	ON_UPDATE_COMMAND_UI(ID_VIEW_TOOLBAR, OnUpdateToolBarMenu) 
	ON_WM_MOUSEMOVE()
	ON_WM_INITMENUPOPUP()
	ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_CAPS, OnUpdateKeyIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_SCRL, OnUpdateKeyIndicator)
	ON_COMMAND(IDOK, OnOK)
	ON_COMMAND(IDCANCEL, OnCancel)
	//}}AFX_MSG_MAP
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()

there is the handler for WM_ENTERIDLE message, where CFrameWnd process WM_ENTERIDLE to update status bar. The same scenario is working for CDialog only when it is modal and it is not main application window. Workaround for different situations is handling WM_KICKIDLE. Rest of message map is for handling messages for tool tips and updating user interface (menu and status bar).

Usage

Using CDialogEx is as simple as deriving your dialog class from CDialog. You can use class wizard to derive your dialog from CDialog and then just replace all references to CDialog with CDialogEx. You have to implement OnInitDialog() and call function InitDialogEx() from within it.

BOOL InitDialogEx(BOOL btool tips = FALSE, BOOL bStatusBar = FALSE, 
                  UINT *pIndicators = NULL,
                  UINT nIndicators = 0, UINT uiToolBar = 0, 
                  DWORD dwToolBarStyle = TBSTYLE_FLAT | WS_CHILD | 
                                         WS_VISIBLE | CBRS_TOP | 
                                         CBRS_GRIPPER | CBRS_TOOLTIPS | 
                                         CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

Set btool tips to TRUE if you want to use tool tips. Set bStatusBar to TRUE, if you want to show status bar. If you will not specify pIndicators and nIndicators when bStatusBar is TRUE, then CDialogEx will show default status bar with indicators for Num Lock, Caps Lock and Scroll Lock. Otherwise you can provide definition for you own status bar in these parameters. Parameter uiToolBar is resource ID of your toolbar with styles specified in dwToolBarStyle.

Last thing to do is to add string AFX_IDS_IDLEMESSAGE to your resources. Its ID has to be 57345. This string is shown in the status bar when application is in idle state, usually you can use string like 'Ready'.

The same setup applies for using CPropertySheetEx2. Only function to call from InitDialogEx() has name InitPropertySheetEx2() and one parameter more for resource ID of menu to show. And, off course, you have to derive your pages from CPropertyPageEx2 class.

Demo programs

Demo program CDialogExDemo and CPropertySheetEx2Demo demonstrate using CDialogEx in the different scenarios, as a modal or modeless main application window, or as a child window.

History

  • 24 Sep 2002 - couple of bugs removed, new demo program for CPropertySheetEx2 - credits to Cyril Boutamine and Jonathan de Halleux

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Martin Ziacek
Software Developer (Senior)
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
QuestionStatus Bar on bottom like in IE? Pin
aquawicket30-Oct-06 13:35
memberaquawicket30-Oct-06 13:35 
QuestionDoes not work if statically linking DLL! Pin
misterredtape18-Jul-06 7:50
membermisterredtape18-Jul-06 7:50 
GeneralProblem with dialog menu Pin
one_eddie27-Dec-04 4:20
memberone_eddie27-Dec-04 4:20 
GeneralCombo boxes & CDialogEx Pin
bigkim4-Jan-04 14:33
memberbigkim4-Jan-04 14:33 
GeneralI know its a basic doubt...but still Pin
dendude18-Dec-03 1:31
memberdendude18-Dec-03 1:31 
GeneralStep by step explanation will be useful Pin
bahu bali16-Sep-03 23:33
sussbahu bali16-Sep-03 23:33 
GeneralA bit offtopic. Problems with property sheets and tabs Pin
Bartek Bosowiec8-Jul-03 3:42
sussBartek Bosowiec8-Jul-03 3:42 
Generaluseful! just what i want Pin
Zhuofei Wang7-Jun-03 16:20
memberZhuofei Wang7-Jun-03 16:20 
GeneralStatusBar Pin
Brian Delahunty14-Apr-03 5:01
memberBrian Delahunty14-Apr-03 5:01 
GeneralCool .. plus one question Pin
HMaxF13-Apr-03 19:58
memberHMaxF13-Apr-03 19:58 
Generalis excelent! but... Pin
musaddiq16-Feb-03 3:11
membermusaddiq16-Feb-03 3:11 
Generalmor information: Pin
musaddiq16-Feb-03 3:29
membermusaddiq16-Feb-03 3:29 
GeneralRe: mor information: Pin
musaddiq17-Feb-03 19:12
membermusaddiq17-Feb-03 19:12 
GeneralRe: mor information: Pin
musaddiq17-Feb-03 19:15
membermusaddiq17-Feb-03 19:15 
Generalis excelent! but... Pin
musaddiq16-Feb-03 3:11
membermusaddiq16-Feb-03 3:11 
GeneralDialog in a DLL Pin
Brett Rowbotham24-Jan-03 1:58
memberBrett Rowbotham24-Jan-03 1:58 
GeneralToolbar position Pin
Christian Reichenbach2-Dec-02 14:47
memberChristian Reichenbach2-Dec-02 14:47 
GeneralRe: Toolbar position Pin
tcoder8-Jan-03 18:14
susstcoder8-Jan-03 18:14 
QuestionCReBar Support ? Pin
Jesper Mandal Hansen20-Nov-02 11:16
memberJesper Mandal Hansen20-Nov-02 11:16 
GeneralGood Work Pin
Anonymous18-Nov-02 6:12
sussAnonymous18-Nov-02 6:12 
Questionneed MFC42U.lib?? Pin
Anonymous30-Oct-02 22:52
sussAnonymous30-Oct-02 22:52 
AnswerRe: need MFC42U.lib?? Pin
Martin Ziacek30-Oct-02 23:58
memberMartin Ziacek30-Oct-02 23:58 
GeneralRe: need MFC42U.lib?? Pin
Anonymous24-Jan-03 2:18
sussAnonymous24-Jan-03 2:18 
GeneralRe: need MFC42U.lib?? Pin
Anonymous24-Jan-03 4:15
sussAnonymous24-Jan-03 4:15 
GeneralRe: need MFC42U.lib?? Pin
suntree5-Jun-03 22:02
membersuntree5-Jun-03 22:02 
GeneralNeed bitmapped dialog Pin
Anonymous18-Oct-02 8:45
sussAnonymous18-Oct-02 8:45 
GeneralRe: Need bitmapped dialog Pin
Martin Ziacek18-Oct-02 12:31
memberMartin Ziacek18-Oct-02 12:31 
QuestionHow to assign accelerator keys to menu items? Pin
CBock28-Oct-02 1:02
sussCBock28-Oct-02 1:02 
AnswerRe: How to assign accelerator keys to menu items? Pin
Martin Ziacek8-Oct-02 10:10
memberMartin Ziacek8-Oct-02 10:10 
GeneralPb with CPropertySheetEx2 Pin
Cyril Boutamine11-Sep-02 22:27
sussCyril Boutamine11-Sep-02 22:27 
GeneralRe: Pb with CPropertySheetEx2 Pin
Martin Ziacek12-Sep-02 9:17
memberMartin Ziacek12-Sep-02 9:17 
GeneralRe: Pb with CPropertySheetEx2 Pin
Cyril Boutamine16-Sep-02 6:11
sussCyril Boutamine16-Sep-02 6:11 
GeneralRe: Pb with CPropertySheetEx2 Pin
Martin Ziacek16-Sep-02 10:16
memberMartin Ziacek16-Sep-02 10:16 
GeneralRe: Pb with CPropertySheetEx2 Pin
Cyril Boutamine16-Sep-02 21:36
memberCyril Boutamine16-Sep-02 21:36 
GeneralRe: Pb with CPropertySheetEx2 Pin
Martin Ziacek16-Sep-02 21:46
memberMartin Ziacek16-Sep-02 21:46 
GeneralRe: Pb with CPropertySheetEx2 Pin
Anonymous16-Sep-02 22:19
sussAnonymous16-Sep-02 22:19 
GeneralRe: Pb with CPropertySheetEx2 Pin
Cyril Boutamine17-Sep-02 6:13
memberCyril Boutamine17-Sep-02 6:13 
GeneralRe: Pb with CPropertySheetEx2 Pin
Martin Ziacek17-Sep-02 10:42
memberMartin Ziacek17-Sep-02 10:42 
GeneralProbs with this example Pin
CBock231-Aug-02 4:03
memberCBock231-Aug-02 4:03 
GeneralRe: Probs with this example Pin
Martin Ziacek31-Aug-02 20:54
memberMartin Ziacek31-Aug-02 20:54 
GeneralIt's cool !! Pin
Anonymous3-Jun-02 14:30
memberAnonymous3-Jun-02 14:30 
GeneralRe: It's cool !! Pin
Martin Ziacek5-Jun-02 1:33
memberMartin Ziacek5-Jun-02 1:33 
GeneralResizing and getting real client dimensions... Pin
Jonathan de Halleux30-May-02 6:12
memberJonathan de Halleux30-May-02 6:12 
GeneralRe: Resizing and getting real client dimensions... Pin
Martin Ziacek30-May-02 6:36
memberMartin Ziacek30-May-02 6:36 
GeneralRe: Resizing and getting real client dimensions... Pin
Jonathan de Halleux30-May-02 6:53
memberJonathan de Halleux30-May-02 6:53 
GeneralNice article and... Pin
Nish - Native CPian29-May-02 2:07
memberNish - Native CPian29-May-02 2:07 
GeneralRe: Nice article and... Pin
Martin Ziacek29-May-02 2:08
memberMartin Ziacek29-May-02 2:08 
GeneralRe: Nice article and... Pin
Nish - Native CPian29-May-02 2:20
memberNish - Native CPian29-May-02 2:20 
GeneralRe: Nice article and... Pin
Martin Ziacek29-May-02 2:23
memberMartin Ziacek29-May-02 2:23 
GeneralRe: Nice article and... Pin
Shog929-May-02 11:09
memberShog929-May-02 11:09 

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 | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 29 Sep 2002
Article Copyright 2002 by Martin Ziacek
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid