Solved

Dynamic Toolbars

Posted on 1997-07-30
5
369 Views
Last Modified: 2012-08-14
I need to know how to load a toolbar.bmp file into the CToolbar class at run time.  The bmp file is not a resource therefore I will not have a resource id.  Also it can not be a resource as toolbars will be user defineable and creatable at runtime through a basic maintenance program.  The user can have as many toolbars as they want but can only load one at a time.  Since I don't know what buttons will be in the toolbar I cannot create a resource.  Also the bitmap file created may contain any number of buttons. It's not just one button.
0
Comment
Question by:msherw
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1166336
You can create a CToolBar without any bitmaps or buttons loaded. Then at runtime, you can use CToolBar::GetToolBarCtrl() to retrieve the underlying CToolBarCtrl. You can then create a CBitmap at runtime with which you use the CToolBarCtrl::AddBitmap() function. After loading the bitmap, be sure to also use CToolBarCtrl::AddButton to specify the button information.

0
 

Author Comment

by:msherw
ID: 1166337
Best I can tell CBitmap wants a resource identifier also. I don't have a resource Identifier. The bitmaps in question are not part of the runtime executable either. It is possible that they will be created months after the executable is made. I'm working with Loadimage to get a handle and using the SetBitmap member of CToolbar but all the buttons seem to be disabled with the exception of the first button.  Again since I DON'T HAVE A RESOURCE IDENTIFIER for the bitmap or the buttons I'm using SetButton(NULL, nobuttons) and SetButtonInfo in a for loop just arbitrarily assigning the counter value to the button and image id.  
0
 
LVL 8

Expert Comment

by:gelbert
ID: 1166338
Advice about using CToolBatCtrl::AddBitmap()  was right. MFC provides two implementations of this function one of them takes resource ID as you sad but another takes pointer to CBitmap object which you can create at run-time.
0
 

Author Comment

by:msherw
ID: 1166339
Ok, so I've tried the CBitmap object, the buttons are still disabled even though I have set the state to enabled. If I use       m_wndToolBarCtl.AddButtons( ButtonCount,ptbButton);
it adds the buttons all right and they are enabled but they don't work like buttons. When you press them they do look pressed or anything. So I tried it a different way.  I use m_wndToolBarCtl to add the Bitmap then send a message to the m_wndToolBar which is the CToolBar class to add the buttons
      m_wndToolBar.SendMessage(TB_ADDBUTTONS,(WPARAM)(UINT)ButtonCount,(LPARAM)ptbButton);
It adds them and they act like buttons, the only problem is that everyone except the first is disabled.
Here is my TBButton array
      for (i=0; i < ButtonCount; i++)
      {
            ptbButton[i].iBitmap = i;
            ptbButton[i].idCommand =  i;
              ptbButton[i].fsState = TBSTATE_ENABLED;
            ptbButton[i].fsStyle =  TBSTYLE_BUTTON ;
            ptbButton[i].dwData = 0L;
            ptbButton[i].iString = NULL;

      }

as you can see I have set the state to enabled for all the buttons.  So what's the deal?

      
0
 
LVL 8

Accepted Solution

by:
gelbert earned 70 total points
ID: 1166340
I think your problem is wrong value of command IDs for your buttons. Try to use values in range of 32777-33000. And make sure that you have message handlers for these IDS
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question