Solved

Dynamic Toolbars

Posted on 1997-07-30
5
367 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now