Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - Subclassing CXTPRibbonBar
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Subclassing CXTPRibbonBar

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

Joined: 16 March 2007
Location: United Kingdom
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rhogan Quote  Post ReplyReply Direct Link To This Post Topic: Subclassing CXTPRibbonBar
    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...
}
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


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: 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
Back to Top
Rhogan View Drop Down
Newbie
Newbie
Avatar

Joined: 16 March 2007
Location: United Kingdom
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rhogan Quote  Post ReplyReply Direct Link To This Post 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.

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.141 seconds.