Print Page | Close Window

A derived CXTPToolBar and customization

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=2690
Printed Date: 08 November 2025 at 4:03pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: A derived CXTPToolBar and customization
Posted By: mwest
Subject: A derived CXTPToolBar and customization
Date Posted: 05 August 2005 at 3:25pm
How do you use a custom derived CXTPToolBar class and still keep toolbar customization?

Problem:
Getting an “An unsupported operation was attempted” error when the SaveCommandBars method is executed.

References:
Online Help – use index for ‘SetToolBarClass’
Online Help – use index for ‘cxtpcommandbars’ (look at Add method)
Forum - http://forum.codejock.com/forum_posts.asp?TID=1932&K W=SetToolBarClass

Demonstration:
To see the error, use the ‘Notifications’ sample in ‘…\Samples\CommandBars\Notifications’.  Use a custom Toolbar:
1)  Create a new toolbar class


class CXTPToolBarEx : public CXTPToolBar 
{
public:
    DECLARE_DYNCREATE(CXTPToolBarEx)


    CXTPToolBarEx();
    virtual ~CXTPToolBarEx();

protected:
    //{{AFX_MSG(CXTPToolBarEx)
        // NOTE - the ClassWizard will add and remove member functions here.
        //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};


2)  Define it:


IMPLEMENT_DYNCREATE(CXTPToolBarEx, CXTPToolBar)

BEGIN_MESSAGE_MAP(CXTPToolBarEx, CXTPToolBar)
    //{{AFX_MSG_MAP(CXTPToolBarEx)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

CXTPToolBarEx::CXTPToolBarEx()
{

}

CXTPToolBarEx::~CXTPToolBarEx()
{

}


3.  Switch the Toolbars in CMainFrame::OnCreate().  Can do this in two different ways.  Both produce the same error:

A. 

CXTPToolBar* pToolBar = (CXTPToolBar*)
        pCommandBars->Add(_T("Standard"), xtpBarTop, RUNTIME_CLASS(CXTPToolBarEx));
    if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to create toolbar\n");
        return -1;
    }


B.

pCommandBars->SetToolBarClass(RUNTIME_CLASS(CXTPToolBar Ex));
CXTPToolBar* pToolBar = (CXTPToolBar*)
        pCommandBars->Add(_T("Standard"), xtpBarTop);
    if (!pToolBar || !pToolBar->LoadToolBar(IDR_MAINFRAME))
    {
        TRACE0("Failed to create toolbar\n");
        return -1;
    }

   
4.  Build and run it.  When you try to close the app, it will give you the error.

Please help.  I need to find a fix for this fairly soon.  Any help is appreciated.  Thanks! 




Replies:
Posted By: Oleg
Date Posted: 05 August 2005 at 11:10pm

You must instead  DECLARE_DYNCREATE/IMPLEMENT_DYNCREATE

use

DECLARE_XTP_COMMANDBAR/IMPLEMENT_XTP_COMMANDBAR

 

ps. For custom CXTPControl:

DECLARE_XTP_CONTROL/IMPLEMENT_XTP_CONTROL



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: mwest
Date Posted: 08 August 2005 at 4:19pm
Oleg,

Thanks for the reply.  Your PS saved me!

However, I found out the hard way that one should not use pointers to controls in a toolbar.  It seems that LoadCommandBars() creates new objects.  So, anytime I need to reference a control, I have to use the FindControl() method.  It is no big deal and it is better programming methodology.

Thanks again for your help!!!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net