Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Custom class derived from CExtToolControlBar Collapse All
Subject Author Date
Chris Mason Apr 9, 2008 - 5:19 AM

Hi.


 


We have a custom class that is derived from CExtToolControlBar. This class overrides OnQueryMultiRowLayout(). However, due to the nature of our program we have to create each control bar at runtime (the number of bars is based on an XML file and therefore this may not be consistent). We have been able to create these bars using the following code:


 


CRuntimeClass *pRTC = RUNTIME_CLASS( CAppToolControlBar);

CAppToolControlBar *pBar = STATIC_DOWNCAST(CAppToolControlBar, pRTC->CreateObject());


 


However, when Create() is called our derived class is not being created, only a standard CExtToolControlBar is. Now our questions are a) is the above way the best way in which to create a control bar dynamically at runtime, and b) why does our custom class not get created.


Any help would be gratefully recieved.

Technical Support Apr 9, 2008 - 10:21 AM

The following code

CAppToolControlBar * pBar = STATIC_DOWNCAST( CAppToolControlBar, pRTC->CreateObject() );
will work correctly without assertion failures and create a true instance of your CAppToolControlBar class only if this class has DECLARE_DYNCREATE / IMPLEMENT_DYNCREATE or DECLARE_SERIAL / IMPLEMENT_SERIAL macros inserted into its declaration and implementation. If the line of code above is executed correctly without an assertion failure, then your application instantiates and creates a CAppToolControlBar object rather than a CExtToolControlBar object. But you wrote you had detected the presence of a CExtToolControlBar object instead of CAppToolControlBar. You should try to ensure whether a pointer to the CExtToolControlBar object detected during debugging in your project is the same pBar pointer created by the line of code above. The CExtControlBar::Create() method works equally with the CExtControlBar, CExtToolControlBar and your CAppToolControlBar classes and any other CExtControlBar-derived classes. This method is invoked for the already instantiated control bar object. You detect the type of object specified by this pointer during step by step debugging of some method of this object, you should open the Watch window in your Visual Studio and review this pointer variable in it. Please expand the tree of this variable until the members of topmost base class become visible. This is the CObject class in the case of MFC/Prof-UIS classes. You will see a virtual table pointer as the first member of the CObject class. It should be CAppToolControlBar::vtbl rather than CExtToolControlBar::vtbl.


Chris Mason Apr 9, 2008 - 7:25 AM

No worries have sorted this myself.