behaviour when adding custom buttons to CMFCToolBar with CMFCToolBar::ReplaceButton?
-
I have a CMFCToolbar that contains a CMFCToolBarMenuButton (which will display a drop down menu). I add my custom button like this (not production code)
LRESULT CMainFrame::OnToolbarReset(WPARAM wp, LPARAM)
{
UINT uiToolBarId = (UINT) wp;if (uiToolBarId == IDR\_TOOLBAR1 ) { CMenu m\_Menu; m\_Menu.LoadMenu(IDR\_OUTPUT\_POPUP); MyToolbarMenuButton menuButton(ID\_BUTTON32771, m\_Menu.GetSubMenu(0)->GetSafeHmenu(), GetCmdMgr()->GetCmdImage(ID\_BUTTON32771, FALSE), NULL, FALSE); m\_MaxToolbar.ReplaceButton(ID\_BUTTON32771, menuButton); } return 0;
}
Eventually, in the framework, I get to this function :
int CMFCToolBar::InsertButton(const CMFCToolBarButton& button, INT_PTR iInsertAt)
{
/*1*/ CRuntimeClass* pClass = button.GetRuntimeClass();
ENSURE(pClass != NULL);/*2*/ CMFCToolBarButton* pButton = (CMFCToolBarButton*) pClass->CreateObject();
ENSURE(pButton != NULL);ASSERT\_VALID(pButton); pButton->CopyFrom(button); INT\_PTR iIndex = InsertButton(pButton, (int) iInsertAt); if (iIndex < 0) { delete pButton; } return(int) iIndex;
}
Question: If I understand correctly the code at line 1 and 2 in CMFCToolBar::InsertButton, it will loose all information about my own derived class MyToolbarMenuButton by getting the Runtime class and casting that to the base class ? The issue is that I want to override some virtual method in CMFCToolBarButton but when I add my own class, it is not actually "instantiated". Thanks.
I'd rather be phishing!