Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - A derived CXTPToolBar and customization
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

A derived CXTPToolBar and customization

 Post Reply Post Reply
Author
Message
mwest View Drop Down
Newbie
Newbie
Avatar

Joined: 13 June 2005
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote mwest Quote  Post ReplyReply Direct Link To This Post Topic: A derived CXTPToolBar and customization
    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! 

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
mwest View Drop Down
Newbie
Newbie
Avatar

Joined: 13 June 2005
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote mwest Quote  Post ReplyReply Direct Link To This Post 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!!!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.