Click to See Complete Forum and Search --> : incorrect rebar height when window is restored from a minimized state


supernater
October 11th, 2009, 06:54 PM
I have a rebar that has two toolbars inserted into it on the same row, so the toolbars are not stacked. The toolbar heights are 27. When I minimze and then restore the window from the minimized state, the rebar height is wrong, the height of the rebar suggested that both bands are stacked on top of one another even though, visibly, they aren't. It doesn't matter how I retreive the height of the rebar, I can use GetWindowRect and calculate the height from that, or I can use RB_GETBARHEIGHT. Both methods show the height of the rebar at 27 prior to minimizing and 54 when I restore from a minimized state.

I sent the message RB_GETROWHEIGHT before I minimzed and after I restored from a minimzed state, sure enough, the row count was 1 before minimizing and 2 after restoring from a minimized state.

I do not have the RBS_AUTOSIZE style on my rebar when I create it. Does anyone know why this would be happening? Below is my code for creating the toolbars and rebar.



HWND CreateToolbar1( HWND hWndParent ){

// Define some constants.
const int ImageListID = 0;
const int numButtons = 1;
const DWORD buttonStyles = BTNS_AUTOSIZE;
const int bitmapSize = 16;

// Create the toolbar.
// specify CCS_NOPARENTALIGN and CCS_NORESIZE to prevent toolbar from aligning to the top, CCS_NODIVDER gets rid of the line at the top of the toolbar
HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, L"toolbar1",
WS_CHILD | TBSTYLE_WRAPABLE | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER,
0, 0, 0, 0,
hWndParent, (HMENU)ID_TOOLBAR1, (HINSTANCE)GetWindowLong( hWndParent, GWL_HINSTANCE ), NULL);


// Create the imagelist.
HIMAGELIST hImageList = ImageList_Create(
bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR16 | ILC_MASK, // Ensures transparent background.
numButtons, 0);

// Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)ImageListID, (LPARAM)hImageList);

// Load the button images.
SendMessage(hWndToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);

// Initialize button info.
TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(STD_FILENEW, ImageListID), ID_FILE_NEW, TBSTATE_ENABLED, buttonStyles, {0}, 0, NULL },
};

// Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons);

// Tell the toolbar to resize itself, and make it visible.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE);
return hWndToolbar;
}



HWND CreateToolbar2( HWND hWndParent){

// Define some constants.
const int ImageListID = 0;
const int numButtons = 1;
const DWORD buttonStyles = BTNS_AUTOSIZE;
const int bitmapSize = 16;

// Create the toolbar.
// CCS_NOPARENTALIGN and CCS_NORESIZE prevent toolbar from aligning to the top
HWND hWndToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, L"toolbar2",
WS_CHILD | TBSTYLE_WRAPABLE |TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER| WS_CLIPCHILDREN ,
0, 0, 0, 0,
hWndParent, (HMENU)ID_TOOLBAR2, (HINSTANCE)GetWindowLong( hWndParent, GWL_HINSTANCE ), NULL);


// Create the imagelist.
HIMAGELIST hImageList = ImageList_Create(
bitmapSize, bitmapSize, // Dimensions of individual bitmaps.
ILC_COLOR32 | ILC_MASK, // Ensures transparent background.
numButtons, 0);


// Load the Bitmap and check the return to make sure it's been loaded
// Bitmap size is 112x16, so it contains seven 16x16 images
HANDLE hbmp = LoadImage((HINSTANCE)GetWindowLong( hWndParent, GWL_HINSTANCE ), MAKEINTRESOURCE(IDB_BITMAP2), IMAGE_BITMAP, 96, 16, LR_SHARED);
HANDLE hbmpMask = LoadImage((HINSTANCE)GetWindowLong( hWndParent, GWL_HINSTANCE ), MAKEINTRESOURCE(IDB_BITMAP3), IMAGE_BITMAP, 96, 16, LR_SHARED);


// Add the bitmap into the imagelist and check the return
ImageList_Add( hImageList, (HBITMAP)hbmp, (HBITMAP)hbmpMask);

// Set the image list.
SendMessage(hWndToolbar, TB_SETIMAGELIST, (WPARAM)ImageListID, (LPARAM)hImageList);

// Initialize button info.
TBBUTTON tbButtons[numButtons] =
{
{ MAKELONG(0, ImageListID), ID_FORMAT_BOLD, TBSTATE_ENABLED, buttonStyles, {0}, 0, NULL },
};

// Add buttons.
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS, (WPARAM)numButtons, (LPARAM)&tbButtons);

// Tell the toolbar to resize itself, and show it.
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hWndToolbar, TRUE);

// clean up bitmaps
DeleteObject(hbmp);
DeleteObject(hbmpMask);
return hWndToolbar;
}



HWND CreateRebar( HWND hWnd ){

// Create the rebar.
HWND hRebar = CreateWindowEx(WS_EX_TOOLWINDOW,
REBARCLASSNAME,
L"rebar",
WS_CHILD | WS_VISIBLE | RBS_DBLCLKTOGGLE |
RBS_REGISTERDROP | WS_CLIPCHILDREN | RBS_VARHEIGHT | CCS_NODIVIDER ,
0,0,0,0,
hWnd, NULL,
(HINSTANCE)GetWindowLong( hWnd, GWL_HINSTANCE ),
NULL);

// Initialize band info used by both bands.
REBARBANDINFO rbBand;
memset(&rbBand, 0, sizeof(REBARBANDINFO));
rbBand.cbSize = sizeof(REBARBANDINFO) ;
rbBand.fMask =
RBBIM_STYLE // fStyle is valid.
| RBBIM_CHILD // hwndChild is valid.
| RBBIM_CHILDSIZE // child size members are valid.
| RBBIM_SIZE; // cx is valid
rbBand.fStyle = RBBS_CHILDEDGE | RBBS_TOPALIGN; //RBBS_FIXEDSIZE |

HWND hToolbar1 = CreateToolbar1(hRebar);
HWND hToolbar2 = CreateToolbar2(hRebar);

// Get the height of the Toolbar#1.
DWORD dwBtnSize = (DWORD)SendMessage(hToolbar1, TB_GETBUTTONSIZE, 0,0);

// Set values unique to the band with the toolbar.
rbBand.hwndChild = hToolbar1;
rbBand.cyChild = LOWORD(dwBtnSize);
rbBand.cxMinChild = 0; // this value must be less than the value of the cxMinChild in the next section
rbBand.cyMinChild = LOWORD(dwBtnSize);
rbBand.cx = 320;

// Add the band that has the toolbar.
SendMessage(hRebar, RB_INSE*****D, (WPARAM)-1, (LPARAM)&rbBand);

// Set values unique to the band with the toolbar.
rbBand.hwndChild = hToolbar2;
rbBand.cyChild = LOWORD(dwBtnSize);
rbBand.cxMinChild = 0; // this value must be greater than the value of the cxMinChild in the previous section
rbBand.cyMinChild = LOWORD(dwBtnSize);
rbBand.cx = 230;

// Add the band that has the toolbar.
SendMessage(hRebar, RB_INSE*****D, (WPARAM)-1, (LPARAM)&rbBand);

return hRebar;
}

hoxsiew
October 12th, 2009, 08:48 AM
I've tried pasting your code into a project to see what you are talking about, but I don't have much to work with. I added a few of my own resources for IDB_BITMAP1, etc. and got it to compile, but I'm not seeing your behavior. The ReBars minimize and maximize as the should.

Perhaps attaching a zipped minimal project that duplicates this behavior would be more helpful.

supernater
October 12th, 2009, 10:05 PM
hey hoxsiew

Thanks for taking the time to look at my project. I've attached a watered down version of my code that generates the error I was talking about when run in Visual Studio 2008. I inserted a breakpoint in the Resize Window function . When you minimize the window, the row number is 1 and the height is 27, but when the window is restored, the row number is 2 and the height is 54.

hoxsiew
October 13th, 2009, 08:27 AM
Thanks for the attachment, but I compiled and ran it as presented and still don't have the problem you described. Could it be a OS or theme related issue? I'm running plain vanilla XPSP3 w/Standard XP theme.

supernater
October 13th, 2009, 06:52 PM
You didn't see anything? Dang. What I'm seeing is that the rebar height won't change it's appearance, it's the number of rows that changes when the entire window is restored from a minimized position, the rebar looks the same.

I set a breakpoint at the end of the ResizeWindow function and I see that when the entire window is restored from a minimized position that the number that the row number is 2. This make resizeing the edit control that I plan to put below the rebar difficult, since the wrong height is constantly calculated.

I'm running Windows XP Professional SP2 plain vanilla standard theme

I guess the only thing I can do is try to compile this on another computer.