NO

Author Topic: Problem with inserting toolbars in a rebar control  (Read 3447 times)

Offline CFred

  • Member
  • *
  • Posts: 36
Problem with inserting toolbars in a rebar control
« on: July 26, 2023, 01:02:25 PM »
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
Code: [Select]
HWND hRebar;
hRebar = MakeRebar(hwnd);
InsertToolbar1(hRebar);
InsertToolbar2(hRebar);
         

Each function looks like this:

Code: [Select]
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):

Code: [Select]
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
Code: [Select]
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Problem with inserting toolbars in a rebar control
« Reply #1 on: July 26, 2023, 08:56:12 PM »
From MS here.
Quote from: MS
RB_SETBARINFO message
Sets the characteristics of a rebar control.

Parameters
wParam Must be zero.
lParam   Pointer to a REBARINFO structure that contains the information to be set. You must set the cbSize member of this structure to sizeof(REBARINFO) before sending this message.
You have to get used to read better the documentation.
Code: [Select]
BOOL CreateABand(HWND hwndRebar, HWND hwndToolbar)
{

REBARINFO rbi;
REBARBANDINFO rbbi;
SIZE s;

SendMessage(hwndToolbar, TB_GETMAXSIZE, 0, (LPARAM)&s);

rbi.cbSize = sizeof(rbi); //You have forget this initialization!!!!
if (SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi) == 0)
{
MessageBox(0, "Could not set up the band", "WARNING", MB_OK | MB_ICONINFORMATION);
return FALSE;
}
    ...
This is the 2nd wish, remember that you have only 3...  8)
« Last Edit: July 26, 2023, 09:02:15 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline CFred

  • Member
  • *
  • Posts: 36
Re: Problem with inserting toolbars in a rebar control
« Reply #2 on: July 27, 2023, 12:34:49 PM »
@frankie: Thanks for your help - I don't know how I missed that one!

I was not sure whether I should have posted the question in the section for beginners questions or in the section for Windows questions.