Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - About Dynamically Remove Button From ToolBar
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

About Dynamically Remove Button From ToolBar

 Post Reply Post Reply
Author
Message
martypku View Drop Down
Newbie
Newbie


Joined: 17 September 2006
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote martypku Quote  Post ReplyReply Direct Link To This Post Topic: About Dynamically Remove Button From ToolBar
    Posted: 19 September 2006 at 11:52pm
I want to remove button from a toolbar dynamically.
 
I use the following code:
 
  CXTPControl* pControl = pToolBar->GetControls()->FindControl(nCmdID);
  if(pControl == NULL) continue;
  pToolBar->GetControls()->Remove(pControl);
 
If I remove all buttons from a toolbar, I want to remove the toolbar also. So I write:
 
  int nTbBtnCount = pToolBar->GetControls()->GetCount();
  if(nTbBtnCount  == 0)
  {
   pToolBar->GetControls()->ClearOriginalControls();
   GetCommandBars()->Remove(pToolBar);
  }
 
This is supposed to be right. However, I find that when the toolbar is visible(sometimes it is not the only case), the toolbar buttons include "close" and "toolbar options" buttons, which are system buttons. So my question is how I know the toolbar has no my own button.
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: 20 September 2006 at 1:16am
Hello,
 
You can add some method which loop  controls and check if control with pControl->IsTemporary()  == FALSE exists.
 
BOOL HasButtons(CXTPToolBar* pToolBar)
{
  for (int i = 0; i < pToolBar->GetControls()->GetCount(); i++) 
  {
     if (!pToolBar->GetControl(i)->IsTemporary())
        return TRUE;
  }
  return FALSE: 
}
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
martypku View Drop Down
Newbie
Newbie


Joined: 17 September 2006
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote martypku Quote  Post ReplyReply Direct Link To This Post Posted: 20 September 2006 at 1:43am
Thanks, it works!
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.157 seconds.