views:

264

answers:

3

I am having issues with creating my own Toolbar inside the Mainframe. I have bitmaps of buttons which I want to use for my own Toolbar but the problem is that the Toolbar displays inside the View of my SDI application. Here is a pic of the incorrectly displayed Toolbar.

http://www.flickr.com/photos/14402427@N02/3409050475/

Here is the code inside the OnCreate function of the Mainframe class : I also have a

// CToolBarCtrl m_wndToolBar; declared inside the MainFrame.h class.


      if(m_wndToolBar.Create(WS_CHILD |  TBSTYLE_FLAT | WS_VISIBLE | CBRS_TOP
     | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC
            ,CRect(0,0,250,50),this,0))
    {
     TRACE0("Failed to create toolbar\n");
     return -1;      // fail to create
    }

       TBBUTTON       tbbutton[3] = {0};
      CSize        button_size(90,90);      
      CSize        bitmap_size(80,80);     

      //m_wndToolBar.AddStrings("String 1\0String 2\0String 3\0");

      tbbutton[0].iBitmap                  = 0;      
      tbbutton[0].idCommand            = ID_CONNECT;
    tbbutton[0].fsState                  = TBSTATE_ENABLED;      
      tbbutton[0].fsStyle                  = TBSTYLE_BUTTON;
      tbbutton[0].dwData                  = 0;     
      tbbutton[0].iString                  = 0;

      tbbutton[1].iBitmap                  = 1;      
      tbbutton[1].idCommand            = ID_DISCONNECT;
    tbbutton[1].fsState                  = TBSTATE_ENABLED;       
      tbbutton[1].fsStyle                  = TBSTYLE_BUTTON;
    tbbutton[1].dwData                  = 0;     
      tbbutton[1].iString                  = 1;

      tbbutton[2].iBitmap                  = 2;      
      tbbutton[2].idCommand              = ID_STOP;
    tbbutton[2].fsState                  = TBSTATE_ENABLED;      
      tbbutton[2].fsStyle                  = TBSTYLE_BUTTON   ;
    tbbutton[2].dwData                  = 0;     
      tbbutton[2].iString                  = 2;

m_wndToolBar.SetButtonSize(button_size);
m_wndToolBar.SetBitmapSize( bitmap_size);

m_wndToolBar.AddButtons(3,tbbutton);
m_wndToolBar.AddBitmap(1,IDB_BITMAP1);
m_wndToolBar.AddBitmap(1,IDB_BITMAP2);
m_wndToolBar.AddBitmap(1,IDB_BITMAP3);

return TRUE;
A: 

From your image it seems that it is not painted or not painted correctly, did you try adding bitmaps first and then adding buttons? or can you call AutoSize on the m_wndToolbarBar.?

Ismael
Thanks for the advice. I tried what you had suggested in that calling the AddBitmap method first then calling AddButtons but what happens is that I am getting a semi working Toolbar but inside the View or client area and not part of the Frame at the top just below the menus.
Sorry I don't have VC 6 at hand. What I'd do is to create a new MFC SDI project with a toolbar and then copying the flags and the initialization code used by the MFC Wizard.
Ismael
A: 

Thanks for the reply and help. Unfortunately I tried your suggestions and could not get a Toolbar to properly display inside the Mainframe pane. Appreciate the help

A: 

Add a call to DockControlBar(&m_wndToolBar) just before the return.

Anthony Williams