Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamic Toolbars

Posted on 1997-07-30
5
Medium Priority
?
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 140 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

722 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