Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. behaviour when adding custom buttons to CMFCToolBar with CMFCToolBar::ReplaceButton?

behaviour when adding custom buttons to CMFCToolBar with CMFCToolBar::ReplaceButton?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups