Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Toolbar Creation Question In Visual C++ 5.0

Posted on 1997-12-07
5
Medium Priority
?
352 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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…
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.

618 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