Code:
//common controls are initiated in the main function
HWND CreateToolbar(HWND hwnd)
{
// Create the toolbar.
HWND hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | TBSTYLE_WRAPABLE | CCS_NORESIZE ,
0, 0, 0, 0,
hwnd, NULL, (HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE), NULL);
if (hToolbar == NULL)
{
MessageBoxW( hwnd, L"Toolbar not created", NULL, MB_OK ); //Check return value of status bar to make sure it's been created
return false;
}
// Tell the toolbar to resize itself, and show it.
SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(hToolbar, TRUE);
return hToolbar;
}
HWND CreateRebar (HWND hwnd)
{
// Create the rebar.
HWND hRebar = CreateWindowEx(WS_EX_TOOLWINDOW,
REBARCLASSNAME,
NULL,
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN | RBS_VARHEIGHT |
CCS_NODIVIDER | RBS_BANDBORDERS,
0,0,0,0,
hwnd,
NULL,
(HINSTANCE)GetWindowLong( hwnd, GWL_HINSTANCE ),
NULL);
if (hRebar == NULL)
{
MessageBoxW( hwnd, L"Rebar not created", NULL, MB_OK ); //Check return value of status bar to make sure it's been created
return false;
}
REBARINFO ri;
ri.cbSize = sizeof (ri);
ri.fMask = 0;
ri.himl = NULL;
SendMessage( hRebar, RB_SETBARINFO, 0, (LPARAM)&ri);
HWND hToolbar = CreateToolbar(hRebar);
if (hToolbar == NULL)
{
MessageBoxW( hwnd, L"Toolbar not created (rebar function)", NULL, MB_OK ); //Check return value of status bar to make sure it's been created
return false;
}
REBARBANDINFO rbBand;
rbBand.cbSize = sizeof(REBARBANDINFO);
rbBand.fMask = RBBIM_CHILDSIZE | RBBIM_CHILD;
rbBand.hwndChild = hToolbar;
rbBand.cyMaxChild = 500;
rbBand.cyMinChild = 100;
rbBand.cyChild = 200;
rbBand.cx = 200;
if(!SendMessage(hRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand))
MessageBeep(0);
return hRebar;
}