Print Page | Close Window

Subclassing CXTPRibbonBar

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=7140
Printed Date: 01 October 2024 at 8:37pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Subclassing CXTPRibbonBar
Posted By: Rhogan
Subject: Subclassing CXTPRibbonBar
Date Posted: 15 May 2007 at 12:52pm
I would like to create a subclass of CXTPRibbonBar with its own message map so it can create itself and handle the message processing. Yes, I can have my main window do all this, but I prefer to work things in this manner. I have most things working, but not having used MFC for a few years, I forget how to get my message map working. I could post my code here, but perhaps it is better if some tech would just post some brief tips. Here is some of my code. Please advise on how to get things working so the message map works and constructor will create the ribbon groups without giving an exception:

class _XTP_EXT_CLASS CRibbon: public CXTPRibbonBar
{
DECLARE_DYNCREATE(CRibbon)
DECLARE_MESSAGE_MAP()
public:
CRibbon();
int OnCreate(LPCREATESTRUCT lpCreateStruct);
bool Init();
protected: // message map functions
afx_msg void OnRibbonTabChanged(NMHDR*, LRESULT*);
};

IMPLEMENT_DYNCREATE(CRibbon, CXTPRibbonBar)

BEGIN_MESSAGE_MAP(CRibbon, CXTPRibbonBar)
ON_NOTIFY(TCN_SELCHANGE, XTP_ID_RIBBONCONTROLTAB, OnRibbonTabChanged)
END_MESSAGE_MAP()

CRibbon::CRibbon()
{
TRACE("CRibbon constructor\n");
// unable to create ribbon elemtns here else exception
}

int CRibbon::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// this function is never called; surprising

if (CXTPRibbonBar::OnCreate(lpCreateStruct) == -1)
    return -1;

// I notice source uses SetupHook() here; do I need it?

return 0;
}

// my main window calls pRibbon->Init() after
// creating object since constructor cannot create
// elements without giving exception
bool CRibbon::Init()
{
CMainFrame* pMainFrame = (CMainFrame*) AfxGetMainWnd();
CXTPCommandBars* pBars = pMainFrame->GetCommandBars();

// start creating everything...
}



Replies:
Posted By: Oleg
Date Posted: 16 May 2007 at 5:55am
Hi,
 
OnCreate never called because you didn't add ON_WM_CREATE() in message map.
e.


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


Posted By: Rhogan
Date Posted: 16 May 2007 at 9:43pm
"The message map shown in the source code is just a stripped down version of the original, which actually features ON_WM_CREATE()." Or at least, that is what I was about to post until I looked at the actual source file and -- bingo -- you got it right, ON_WM_CREATE() was missing. Thank you for unsticking my brain there.




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