CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Adding controls to a CToolBar



    I have managed to add a Static control and a ComboBox to the control.

    However when I try and add a third control. As spin control the control the ToolBar goes all thin and only really

    properly docks at the sides of the parent.

    Does anyone have any clues as to why this would occur. I dont think it has anything to do do with the the fact it is a

    CSpinCtrl, because the problem occurs at the "SetButtonInfo" stage

    Simon Pettman

    _____________example OnCreate() in Main Frame.________________________

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

    {

    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)

    return -1;

    if (!m_wndToolBar.Create(this) ||

    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))

    {

    TRACE0("Failed to create toolbar\n"

    return -1; // fail to create

    }

    if (!m_wndToolBar2.Create(this,WS_CHILD|WS_VISIBLE|CBRS_TOP,IDR_FREQ_TOOL) ||

    !m_wndToolBar2.LoadToolBar(IDR_FREQ_TOOL))

    {

    TRACE0("Failed to create toolbar\n"

    return -1; // fail to create

    }

    CRect rect;

    int index=0;

    while(m_wndToolBar2.GetItemID(index)!=ID_FREQ_TOOL_STATIC)

    index++;

    m_wndToolBar2.SetButtonInfo(index,ID_FREQ_TOOL_STATIC,

    TBBS_SEPARATOR,100);

    m_wndToolBar2.GetItemRect(index,&rect);

    rect.top+=4;

    m_wndToolBar2.m_staticFreq.Create("Frequency",WS_CHILD|

    WS_VISIBLE|SS_RIGHT,rect,

    (CWnd*) &m_wndToolBar2,ID_FREQ_TOOL_STATIC);

    index=0;

    while(m_wndToolBar2.GetItemID(index)!=ID_FREQ_TOOL_COMBO)

    index++;

    m_wndToolBar2.SetButtonInfo(index,ID_FREQ_TOOL_COMBO,

    TBBS_SEPARATOR,250);

    m_wndToolBar2.GetItemRect(index,&rect);

    // rect.top+=4;

    m_wndToolBar2.m_comboFreq.Create(WS_CHILD|

    WS_VISIBLE|SS_RIGHT,rect,

    (CWnd*) &m_wndToolBar2,ID_FREQ_TOOL_COMBO);

    index=0;

    while(m_wndToolBar2.GetItemID(index)!=ID_FREQ_TOOL_SPIN)

    index++;

    m_wndToolBar2.SetButtonInfo(index,ID_FREQ_TOOL_SPIN,

    TBBS_SEPARATOR,400);

    m_wndToolBar2.GetItemRect(index,&rect);

    m_wndToolBar2.m_spinFreq.Create(WS_CHILD|

    WS_VISIBLE|SS_RIGHT,rect,

    (CWnd*) &m_wndToolBar2,ID_FREQ_TOOL_SPIN);

    if (!m_wndStatusBar.Create(this) ||

    !m_wndStatusBar.SetIndicators(indicators,

    sizeof(indicators)/sizeof(UINT)))

    {

    TRACE0("Failed to create status bar\n"

    return -1; // fail to create

    }

    m_wndStatusBar.SetPaneInfo(0,ID_SEPARATOR,SBPS_STRETCH,200);

    // TODO: Remove this if you don't want tool tips or a resizeable toolbar

    m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |

    CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

    m_wndToolBar.SetBarStyle(m_wndToolBar2.GetBarStyle() |

    CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

    // TODO: Delete these three lines if you don't want the toolbar to

    // be dockable

    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

    m_wndToolBar2.EnableDocking(CBRS_ALIGN_ANY);

    EnableDocking(CBRS_ALIGN_ANY);

    DockControlBar(&m_wndToolBar);

    DockControlBar(&m_wndToolBar2,AFX_IDW_DOCKBAR_TOP);

    return 0;

    }

    ________________________________________________________________


    The first two controls are fine.



  2. #2
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Re: Bizarre Solution, come and see!!!!



    It seems that VC does not like three controls in a row on CToolBars. If you add a normal, and dont call set button info, between controls 2 and 3 three the problem goes away.


    Anyone else have this problem?


    Simon Pettman

    Research Engineer

    Goodmans Loudspeakers Ltd

    [email protected]

  3. #3
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Bizarre Solution, come and see!!!!



    I have about 4 or 5 comboc boxes in row on a CToolBar

    however, I beleive I have some SEPERATORS there as well


    Sally

  4. #4
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Re: Bizarre Solution, come and see!!!!



    Are they consecutive. Or are there any buttons between them?


    Simon P

  5. #5
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Bizarre Solution, come and see!!!!



    5 buttons

    1 separator

    1 button

    1 separator

    3 combo boxes *******

    1 separator

    1 combo box

    1 separator

    1 combo box

    1 separator

    2 buttons

    1 separator

    2 buttons


    works fine for me


    Sally

  6. #6
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    Re: Bizarre Solution, come and see!!!!



    I have found no problems if I have at least one normal button.


    Thanks for you help Sally.


    Simon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured