Toolbar Creation Question In Visual C++ 5.0

I am trying to create a toolbar under MSVC 5.0.  Below I have included some code that I am using.  It creates the toolbar and displays it, but the buttons will not work because there is no command handlers for them.  I am not sure how to attach command handlers to these buttons.  I will describe the process I used to develop this toolbar.

Step 1: I went to resources and inserted a toolbar resouce.  I then created three buttons.  The Buttons are push buttons.

Step 2: In DMainFrame.h I declared CToolBar *d_pToolbar2;
Step 3: In DMainFrame.cpp I added the following code to DMainFrame::OnCreate function.

      //Initialize Toolbar
      d_pToolbar2 = new CToolBar();
      d_pToolbar2->Create(this,WS_CHILD |CBRS_TOP,0x9100);
        //Loads ToolBar From Resouces
      d_pToolbar2->LoadToolBar(IDR_TOOLBAR1);
        //Displays ToolBar In Application
      d_pToolbar2->ShowWindow(SW_SHOWNORMAL);
Step 4: Build Program and execute.  The program will display the toolbar, but I need to attach the buttons to some kind of command handler.

Here are my Questions

Q1:  I would like the buttons to be represented as ID_TESTBUTTON_ONE, ID_TESTBUTTON_TWO, ID_TESTBUTTON_THREE.  Where do I set these properties for that toolbar?

Q2:  In This book I have it shows creating some code like the following

static UINT BASED_CODE buttons[] =
{
    //list toolbar buttons as IDs
};

I added this code, and added the buttons with the IDs I want, but to be expected it said the buttons were undeclared identifiers?

Q3: In this line of code that does the 0x9100 do / stand for in this call?

d_pToolbar2->Create(this,WS_CHILD |CBRS_TOP,0x9100)

Q4:  What do I do next?  Am I on the right track.  How can I finish this off.  

Thank you for your time..
Darrell
larockdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

galkinCommented:
There two way to assign command IDs to toolbar buttons. The first and the simplest one is when you create toolbar in resource editor choose(or type) command id in command IDs combo box. You can follow this way if you know command IDs at compiler time and these IDs will not change at runtime. Toolbar sends WM_COMMAND messages with corresponding id to toolbar owner(which is usually frame window) amd in turn MFC message map mechanism allows you to add handler to any class. If you don't know command ID at compiler time you need to add it to each button by calling CToolBarCtrl function SetCmdID or by sending TB_SETCMDID message to the toolbar window. If you use SDK you you must specify command id for each button when you fill buttons structures array
0
larockdAuthor Commented:
In Visual C++ 5.0, when you create a toolbar and use the "Toolbar Editor" there is no Combobox to define an actual button.  What you have to do is go to menu item under the view menu "Resource Symbols."  Then you have to select the button and VC names the buttons like ID_BUTTON_32xxx then you have to select change, then view use.  Then you can change the ID for it.


Can you please answer Questions 2,3 above for me also.  Thank you.  I appreciate your help...
0
galkinCommented:
I am sorry for not exact answer. There is ID combobox where you can choose ID for each toolbar button. If you don't want to associate toolbar buttons with any menu items do the following. Create dummy meny using resource editor, add menu items you need(ID_TESTBUTTON_ONE, ID_TESTBUTTON_TWO etc.) then go back to the tool bar editor, now you can find these IDs in ID combo box.
If you create toolbat first it is recommended that you use default toolbar ID(it is default parameter - )
Then you need to load toolbar from resources by calling CToolBar::LoadToolBar and passing resource ID of the toolbar you created using resource editor. Then you can specify toolbar style if you have not done yet by CToolBar::SetBarStyle. If you want your toolbar to be dockable you can call       m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY)
CFrameWnd::EnableDocking(CBRS_ALIGN_ANY) and CFrameWnd::DockControlBar(&m_wndToolBar)

      
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
larockdAuthor Commented:


Q2: In This book I have it shows creating some code like the following

                  static UINT BASED_CODE buttons[] =
                  {
                      //list toolbar buttons as IDs
                  };

Q3: In this line of code that does the 0x9100 do / stand for in this call?

 d_pToolbar2->Create(this,WS_CHILD |CBRS_TOP,0x9100)
0
galkinCommented:
If you are using VC++ 5.0 AppWizard generates you code inside CFrameWnd::OnCreate exactly what I wrote. Old VC version when toolbar resource didn't exist can create slightly different code, using bitmap resource as toolbar bitmap and button structures as buttons information. So in this case you must use CToolBar::LoadBitmap to load bitmap from resources and CToolBar::SetButtons to set buttons information. Concerning create you have already mentioned you should use AFX_IDW_TOOLBAR as id. This is neccessary to automaticaly reposition your toolbar when resizing parent frame.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.