Hello guys. I am new to using Rebars from the Common Control Library and I am having problems implementing one that includes a Toolbar. I am inserting two bands in the Rebar; the first one is a Combobox and second one is a Toolbar. The problem is that the Toolbar band always spans over the entire width of the rebar, overlapping all other bands. If anyone can help me I would really appreciate it.
Image of problem:

Source code:
#include <windows.h>
#include <CommCtrl.h>
#include <string>
#pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
::HINSTANCE g_hInstance = NULL;
// function fwd decls.
::HWND createWindow();
::HWND createRebar(::HWND hParentWnd);
::HWND createToolbar(::HWND hParentWnd);
::HWND createCombo(::HWND hParentWnd);
::LRESULT CALLBACK windowProc(::HWND hWnd, ::UINT msg, ::WPARAM wParam, ::LPARAM lParam);
void insertToolbarButton(::HWND hWndToolbar, std::string text);
void insertRebarBand(::HWND hWnd, ::HWND hWndChild, std::string label);
::HWND g_hWndWindow;
::HWND g_hWndRebar;
::HWND g_hWndToolbar;
::HWND g_hWndCombo;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char* szCmdLine, int iCmdShow) {
g_hInstance = hInstance;
g_hWndWindow = createWindow();
// Initialize common controls.
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;
InitCommonControlsEx(&icex);
// Create Combobox
g_hWndCombo = createCombo(g_hWndWindow);
// Create Toolbar
g_hWndToolbar = createToolbar(g_hWndWindow);
// Insert 3 Toolbar buttons
insertToolbarButton(g_hWndToolbar, "New");
insertToolbarButton(g_hWndToolbar, "Open");
insertToolbarButton(g_hWndToolbar, "Save");
// Create Rebar
g_hWndRebar = createRebar(g_hWndWindow);
// Insert Rebar Bands
insertRebarBand(g_hWndRebar, g_hWndCombo, "");
insertRebarBand(g_hWndRebar, g_hWndToolbar, "");
MSG msg = { 0 };
while ((GetMessage(&msg, NULL, 0, 0))) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 1;
}
::LRESULT CALLBACK windowProc(::HWND hWnd, ::UINT msg, ::WPARAM wParam, ::LPARAM lParam) {
return DefWindowProc(hWnd, msg, wParam, lParam);
}
::HWND createWindow() {
::WNDCLASS wndClass = { };
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (::HBRUSH)::GetStockObject(GRAY_BRUSH);
wndClass.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wndClass.hIcon = ::LoadIcon(NULL, IDC_ICON);
wndClass.hInstance = g_hInstance;
wndClass.lpfnWndProc = windowProc;
wndClass.lpszClassName = "Window1";
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW | CS_VREDRAW/* | CS_OWNDC | CS_PARENTDC*/;
if (!::RegisterClass(&wndClass))
return 0;
::HWND hWnd = ::CreateWindowEx(0,
"Window1",
"Window1",
WS_OVERLAPPEDWINDOW,
20, 20, 800, 800,
NULL,
(::HMENU)NULL,
g_hInstance,
0);
::ShowWindow(hWnd, SW_SHOW);
::UpdateWindow(hWnd);
return hWnd;
}
::HWND createToolbar(::HWND hParentWnd) {
::HWND hWnd = ::CreateWindowEx(0,
TOOLBARCLASSNAME,
NULL,
WS_CHILD,
0, 0, 0, 0,
hParentWnd,
(::HMENU)NULL,
g_hInstance,
0);
if (!hWnd)
return NULL;
SendMessage(hWnd, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
::HIMAGELIST hImageList = ::ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, 0, 0);
::SendMessage(hWnd, TB_SETIMAGELIST, 0, (::LPARAM)hImageList);
::ShowWindow(hWnd, SW_SHOW);
::UpdateWindow(hWnd);
return hWnd;
}
::HWND createRebar(::HWND hParentWnd) {
::HWND hWnd = ::CreateWindowEx(WS_EX_TOOLWINDOW,
REBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, 0, 0,
hParentWnd,
(::HMENU)NULL,
g_hInstance,
0);
if (!hWnd)
return NULL;
::ShowWindow(hWnd, SW_SHOW);
::UpdateWindow(hWnd);
return hWnd;
}
::HWND createCombo(::HWND hParentWnd) {
::HWND hWnd = ::CreateWindowEx(0,
WC_COMBOBOX,
NULL,
WS_CHILD | CBS_HASSTRINGS | CBS_DROPDOWNLIST,
0, 0, 0, 0,
hParentWnd,
(::HMENU)NULL,
g_hInstance,
0);
if (!hWnd)
return NULL;
::ShowWindow(hWnd, SW_SHOW);
::UpdateWindow(hWnd);
return hWnd;
}
void insertToolbarButton(::HWND hWndToolbar, std::string text) {
static int counter = 4000;
::TBBUTTON tbButton;
tbButton.iBitmap = 0;
tbButton.iString = (int)text.c_str();
tbButton.idCommand = counter++;
tbButton.dwData = 0;
tbButton.fsState = TBSTATE_ENABLED;
tbButton.fsStyle = TBSTYLE_BUTTON;
bool bRes = ::SendMessage(hWndToolbar, TB_INSERTBUTTON, 0, (::LPARAM)&tbButton);
::SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
}
void insertRebarBand(::HWND hWnd, ::HWND hWndChild, std::string label) {
::REBARBANDINFO band;
band.cbSize = sizeof(::REBARBANDINFO);
band.fMask = RBBIM_TEXT | RBBIM_CHILD | RBBIM_STYLE | RBBIM_CHILDSIZE;
band.hwndChild = hWndChild;
band.lpText = (char*)label.c_str();
band.fStyle = RBBS_GRIPPERALWAYS;
band.cxMinChild = 100; // minimum width of child
band.cyMinChild = 80; // minimum height of child
//band.cxHeader = 100;
//band.cx = 0;
::SendMessage(hWnd, RB_INSERTBAND, (::WPARAM)-1, (::LPARAM)&band);
}