Click to See Complete Forum and Search --> : Adding controls to a CToolBar


Simon Pettman
March 30th, 1999, 10:35 AM
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.

Simon Pettman
March 31st, 1999, 02:21 AM
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

pettman.s@gll.co.uk

sally
March 31st, 1999, 03:03 AM
I have about 4 or 5 comboc boxes in row on a CToolBar

however, I beleive I have some SEPERATORS there as well


Sally

Sally
March 31st, 1999, 03:03 AM
I have about 4 or 5 comboc boxes in row on a CToolBar

however, I beleive I have some SEPERATORS there as well


Sally

Simon Pettman
March 31st, 1999, 04:00 AM
Are they consecutive. Or are there any buttons between them?


Simon P

sally
March 31st, 1999, 08:15 PM
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

Sally
March 31st, 1999, 08:15 PM
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

Simon Pettman
April 1st, 1999, 02:59 AM
I have found no problems if I have at least one normal button.


Thanks for you help Sally.


Simon