Solved

Dynamic Toolbars

Posted on 1997-07-30
5
370 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ get user from AD  (VS6) 7 87
C language IDE – Compilers installation 14 75
Getting IP address 8 89
Adding items to a C# list incrementally 5 36
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

820 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