Solved

Toolbar Creation Question In Visual C++ 5.0

Posted on 1997-12-07
5
330 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:larockd
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:galkin
Comment Utility
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
 

Author Comment

by:larockd
Comment Utility
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
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
Comment Utility
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
 

Author Comment

by:larockd
Comment Utility


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
 
LVL 7

Expert Comment

by:galkin
Comment Utility
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
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…

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

9 Experts available now in Live!

Get 1:1 Help Now