?
Solved

Toolbar Creation Question In Visual C++ 5.0

Posted on 1997-12-07
5
Medium Priority
?
351 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
[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
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1175138
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
ID: 1175139
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 150 total points
ID: 1175140
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
ID: 1175141


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
ID: 1175142
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

764 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