CDialogBarEx : A Dialog bar with initialization
Limitations of CDialogBar:
However, one limitation of CDialogBar is it lacks suitable initialisation function such as OnInitDialog() which is available in all standard CDialog derived classes. This creates trouble in subclassing windows controls created through dialog template. We need to subclass windows controls with suitable MFC class objects to send messages to the control and to alter their behaviour. Without the help of MFC supplied classes, changing the property of Active X controls will require complex code, not so easy to comprehend.
With the help of Class Wizard, subclassing the controls created from dialog template, becomes very easy as the Class Wizard automatically adds DDX_Control( CDataExchange* pDX, int nIDC, CWnd& rControl ); statements in DoDataExchange() override of CDialog derived class. DoDataExchange is called by UpdateData( BOOL bSaveandValidate) function, which in turn is called by OnInitDialog() in response to WM_INITDIALOG message.
All these steps of initialising does not automatically occur in the CDialogbBar as it is derived from CControlBar and not from CDialog.
Solution:
We write a class which does the job of initialising the dialog bar, which can be reused whenever we want to create a dialog bar. Let's call this class CDialogBarEx which would provide functionality of initialising the dialog bar.
The function which initialise the dialog bar should normally be called immediately after the dialog bar is created. We can not use OnCreate() override alone, for this purpose as OnCreate is called during the window creation ( before CreateEx returns ) and not after that. We so we just post a custom WM_INITDIALOGBAR message ( WM_USER + 1)) to the dialog bar itself from our override of OnCreate. This assures that handler for WM_INITDIALOGBAR will called immediately after the dialog bar is fully created and ready to use. We also write handler for WM_INITDIALOG bar ( lets call it OnInitHandler() ) which should call a virtual function OnInitDialogBar() and from the same handler we call UpdateData(FALSE) before we call OnInitDialogBar() ;
The bottom line:
- Users of this class can put DDX_Control statements in side DoDataExchange, as done by Class Wizard for CDialog and its derived classes.
- Users can override OnInitDialogBar to perform other custom initialisation.
How to use CDialogBarEx:
- Add files DialogBarEx.h and DialogBarEx.cpp to your Visual C++ project
- Derive your own class ( for example say "CYourClass" ) from CDialogBarEx ;
- Add DDX_Control statements in your override of DoDataExchange as done by class wizard, to subclass the dialog bar controls with MFC classes.
- Override OnInitDialogBar() function to do any further initialisation of this class.
Other steps to create the dialog bar are the same as recommended by MFC documentation..
- Create dialog resource template . Set child property on, visible off.
- Declare one CDialogBarEx derived member in CMainFrame class;
- In the CMainFrame::OnCreate override call create function of CDialogBarEx derived class.
The demo contains both source and sample program. The demo shows how to set hyperlink in dialog bar using CLabel and how to set initial null ( null means not yet defined and not NULL of C++) value in SysDateTime32 control.
ACKNOWLEDGEMENTS:
To make this demo I have used following classes from www.codeguru.com
- CDateTimeCtrl class written by Chris Maunder
- CLabel class downloaded from codeguru with modifications.
- I have also incorporated a modification to CLabel class suggested to me by Ed Dixon of Mountain System Inc. via e-mail.
Comments
Clas Wizard does not know CDialogBar
Posted by Legacy on 02/16/2003 08:00amOriginally posted by: Jason
Clas Wizard does not know CDialogBar. so how do i derive from this class using the wizard? (vc 6.0)
thanks!
ReplyProblem with Windows Me?
Posted by Legacy on 11/26/2002 08:00amOriginally posted by: Ben Katz
Doesnt work in C++.NET (7.0)
Posted by Legacy on 10/11/2002 07:00amOriginally posted by: Mike Pliam
This works great in Visual C++ 6.0. But when I tried to port an app over to C++ 7.0 (C++.NET), I received the following error message pertaining to the message map code in the DialogBarEx.cpp file:
BEGIN_MESSAGE_MAP(CDialogBarEx, CDialogBar)
//{{AFX_MSG_MAP(CDialogBarEx)
ON_WM_CREATE()
ON_MESSAGE(WM_INITDIALOGBAR, InitDialogBarHandler )
//{{AFX_MSG>MAP[
END_MESSAGE_MAP()
error C2440: 'static_cast': cannot convert from 'void(__thiscall CDialogBarEx::*)(WORD,DWORD)' to'LRESULT (__thiscall CWnd::*)(WPARAM,LPARAM)'
Does anybody know how to work around or fix this problem?
Mike Pliam
ReplyCatching SelChange() in Combo Box
Posted by Legacy on 10/30/2000 08:00amOriginally posted by: Petr Jodas
I have class CDirBarDlg which is derived from CDialogBarEx. In this class I have control CComboBoxEx and I need catch message OnSelChange(). How I can do it ? Thanx...
Replydoes CDialogBar work?
Posted by Legacy on 09/30/2000 07:00amOriginally posted by: ali nouri
hi,
ReplyI want to make a structure viewer on the left of an editor(
like the treeView in the VC environment itself) it should be CControlBar derived class but i couldn't make it with a CDialogBar) what should i do?
thnx
How can I draw a Gripper in the DialogBar?
Posted by Legacy on 07/30/2000 07:00amOriginally posted by: Andi Hofmann
I tried to draw a gripper to the DialogBarEx, but overriding OnPaint doesn't work. How can I manage it?
ReplyAnother option
Posted by Legacy on 12/16/1999 08:00amOriginally posted by: Rick Shide