ToolBar Problem

Hi,
I have a ReBar with a Toolbar and a ControlBar. My problem now is that the ControlBar is not directly attached to the toolbar - There is a lot of empty space between them. Please refer to the picture. How can I resolve this?
Thank's
#9370
[269 byte] By [#9370] at [2007-11-19 16:04:43]
# 1 Re: ToolBar Problem
From your bitmap, it appears that the "empty" space is part of the toolbar. What does the toolbar look like when you un-dock it? Have you checked the CRect for the toolbar to verify the size is correct?
Mike Harnad at 2007-11-10 23:54:25 >
# 2 Re: ToolBar Problem
Hi Mike,

thank you for your reply. I cannot un-dock the toolbar because it is not allowed when using a ReBar.
You are rigth, the size of the toolbar is much too large. What can I do to have the correct size?

The code I am using for the ReBar is the following:

if (!m_wndToolBar.CreateEx(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
CBRS_ALIGN_TOP | CBRS_SIZE_DYNAMIC, AFX_IDW_DIALOGBAR))
{
TRACE0("Failed to create dialogbar\n");
return -1; // fail to create
}

if (!m_wndReBar.Create(this) ||
!m_wndReBar.AddBar(&m_wndToolBar) ||
!m_wndReBar.AddBar(&m_wndDlgBar))
{
TRACE0("Failed to create rebar\n");
return -1; // fail to create
}
#9370 at 2007-11-10 23:55:24 >
# 3 Re: ToolBar Problem
I would first try specifying a CRect when you create the toolbar.
Mike Harnad at 2007-11-10 23:56:28 >
# 4 Re: ToolBar Problem
Hi Mike,

when I specify a CRect at creation of the Toolbar, it looks very strange - there are a lot of errors.
I found out, that when I click at the gripper of the toolbar, the dialogbar gets the wanted size. How can I achieve this automatically?

#9370
#9370 at 2007-11-10 23:57:21 >
# 5 Re: ToolBar Problem
Try calling CFrameWnd::RecalcLayout().
Mike Harnad at 2007-11-10 23:58:20 >
# 6 Re: ToolBar Problem
Thank you, but it is not working.

#9370
#9370 at 2007-11-10 23:59:24 >
# 7 Re: ToolBar Problem
What does the bitmap for the toolbar loook like?
Mike Harnad at 2007-11-11 0:00:28 >
# 8 Re: ToolBar Problem
please see attachment

I also did a plain project where I have the same result
#9370 at 2007-11-11 0:01:28 >
# 9 Re: ToolBar Problem
You might want to try this approach instead. It provides more control over the placement.

The following example demonstrates adding a toolbar band (m_wndToolBar) to an existing rebar control (m_wndReBar). The band is described by initializing the rbi structure and then calling the InsertBand member function:
//load bitmap for toolbar background
m_bmap.LoadBitmap(IDB_BITMAP);

//create a toolbar band
m_wndToolBar.Create(this, TBSTYLE_TRANSPARENT | TBSTYLE_FLAT);
m_wndToolBar.LoadToolBar(IDR_MAINFRAME);

REBARBANDINFO rbi;
rbi.cbSize= sizeof(REBARBANDINFO);
rbi.fMask= RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_STYLE | RBBIM_TEXT;
rbi.fStyle= RBBS_GRIPPERALWAYS;
rbi.cxMinChild= 300;
rbi.cyMinChild= 30;
rbi.lpText= "Band #1";
rbi.cch= 7;
rbi.cx= 300;
rbi.hbmBack= (HBITMAP)m_bmap;
rbi.hwndChild= (HWND)m_wndToolBar;
m_wndReBar.InsertBand(-1, &rbi);
Mike Harnad at 2007-11-11 0:02:25 >
# 10 Re: ToolBar Problem
Hi,

I solved it with this code:

CReBarCtrl& refReBarCtrl = m_wndReBar.GetReBarCtrl();
refReBarCtrl.MaximizeBand(1);


Thank's
#9370
#9370 at 2007-11-11 0:03:26 >