Click here to Skip to main content
11,631,212 members (75,472 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
I am creating MDI application. By default it uses by default toolbar resource IDR_MAINFRAME_256 and class
CMFCToolBar
.How to hide and show particular toolbar button. I require this functionality as there are different users with
different user rights are going to use this Software. Please anyone can tell me
How should I show or hide particular toolbar button.
I tried RemoveButton and InsertButton(gives error as cannot use private fuction)

I also tried

TBBUTTONINFO inf;
    inf.cbSize=sizeof(inf);
    inf.dwMask=TBIF_STYLE;
    inf.fsStyle=BTNS_DROPDOWN | BTNS_AUTOSIZE ;
    m_wndToolBar.SendMessage(TB_HIDEBUTTON, ID_TESTVIEW, (LPARAM)&inf); 

but it does not work at all.
Can anyone tell me please how to go about it.
Posted 19-Sep-12 0:12am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
adityarao31 at 19-Sep-12 7:42am
   
My Friend I want to hide button in onc case,show it in another case.RemoveButton works fine,but InsertButton is private function so we cannot use it,So If I use this method how can I show Button again
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I ran into the same problem. It seems that CMFCToolBar does not react on TB_HIDEBUTTON anymore. I think you have to use the visible style on the buttons, e.g.:

void HideButton(CMFCToolBar* pToolBar, int nID, bool bHide)
{ 
    //NOTE: TB_HIDEBUTTON does not work anymore

    const int nIndex = pToolBar->CommandToIndex(nID);
 
    if (nIndex != -1)
    {
        CMFCToolBarButton* pButton = pToolBar->GetButton(nIndex);
        
        if (pButton)
        {
            pButton->SetVisible(!bHide);
 
            pToolBar->AdjustSizeImmediate();
        }
    }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


Advertise | Privacy | Mobile
Web02 | 2.8.150723.1 | Last Updated 10 Feb 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100