I can set up two toolbars in a rebar control by calling separate functions to insert each toolbar into the rebar control.
The toolbars are inserted in the rebar control in response to the WM_CREATE message using
HWND hRebar;
hRebar = MakeRebar(hwnd);
InsertToolbar1(hRebar);
InsertToolbar2(hRebar);
Each function looks like this:
BOOL InsertToolbar1(HWND hwndRebar){
REBARINFO rbi;
REBARBANDINFO rbbi;
HWND hwndToolbar = MakeToolbar(hwndRebar);
SIZE s;
SendMessage(hwndToolbar, TB_GETMAXSIZE, 0, (LPARAM)&s);
// Set the rebar's band information to display the toolbar
rbi.cbSize = sizeof(REBARINFO);
rbi.fMask = 0;
rbi.himl = NULL;
if (SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi) ==0){
MessageBox(0, "Could not set up the band", "WARNING", MB_OK | MB_ICONINFORMATION);
return FALSE;
}
rbbi.cbSize = sizeof(REBARBANDINFO);
rbbi.fMask = RBBIM_CHILD | // Needed to set hwndChild member
RBBIM_CHILDSIZE | //Needed for cxMinChild, cyMinChild, cyChild, cyMaxChild, and cyIntegral
RBBIM_STYLE;
rbbi.fStyle = RBBS_CHILDEDGE | //Put edge at top and bottom of child window
RBBS_BREAK | //Put each band on a new line
RBBS_USECHEVRON | //Show a chevron button if the band is smaller than cxIdeal
// RBBS_VARIABLEHEIGHT | // Allow the rebar control to size the band
RBBS_GRIPPERALWAYS;
rbbi.hwndChild = hwndToolbar;
rbbi.cxMinChild = s.cx; //Minimum width of the child window (toolbar)
rbbi.cyMinChild = s.cy+1; // Minimum height of toolbar
SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbbi);
return TRUE;
}
However, this will increase the size of the program if several different toolbars are to be put in a rebar control. So I tried to reduce the size of the program by using the following function to create each band of the rebar for each toolbar (each toolbar is created in separate functions):
BOOL CreateABand(HWND hwndRebar, HWND hwndToolbar){
REBARINFO rbi;
REBARBANDINFO rbbi;
SIZE s;
SendMessage(hwndToolbar, TB_GETMAXSIZE, 0, (LPARAM)&s);
if (SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi) ==0){
MessageBox(0, "Could not set up the band", "WARNING", MB_OK | MB_ICONINFORMATION);
return FALSE;
}
rbbi.cbSize = sizeof(REBARBANDINFO);
rbbi.fMask = RBBIM_CHILD | // Needed to set hwndChild member
RBBIM_CHILDSIZE | //Needed for cxMinChild, cyMinChild, cyChild, cyMaxChild, and cyIntegral
RBBIM_STYLE;
rbbi.fStyle = RBBS_CHILDEDGE | //Put edge at top and bottom of child window
RBBS_BREAK | //Put each band on a new line
RBBS_USECHEVRON | //Show a chevron button if the band is smaller than cxIdeal
RBBS_VARIABLEHEIGHT | // Allow the rebar control to size the band
RBBS_GRIPPERALWAYS;
rbbi.hwndChild = hwndToolbar;
rbbi.cxMinChild = s.cx; //Minimum width of the child window (toolbar)
rbbi.cyMinChild = s.cy+1; // Minimum height of toolbar
SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbbi);
return TRUE;
}
The function is called in response to the WM_CREATE message using
HWND hRebar;
hRebar = MakeRebar(hwnd);
HWND hToolbar;
hToolbar = MakeToolbar(hRebar);
CreateABand(hRebar, hToolbar);
to insert one toolbar. In theory the last two lines can be repeated (with slight changes) to create and insert more toolbars in the rebar control as needed.
However this produces the message "Could not set up the band".
I have spent a lot of time trying to resolve this issue because this function is very similar to those that add each toolbar separately to the rebar control and I cannot see what is wrong with my code.
How should I modify the function CreateABand() to avoid this error? The full code is attached and this includes the functions for both of these approaches.