I'm trying to migrate fully working win32 code on visual studio 6 to visual studio 2010. It seems there is some problem with Rebar. Below are my code that working fine on visual studio 6.
HWND hwndRebar = NULL;
REBARINFO rbi;
REBARBANDINFO rbbi;
HWND hwndChild;
RECT rc;
LPSTR lpszTemp;
UINT nHeight;
hwndRebar = CreateWindowEx( WS_EX_TOOLWINDOW,
REBARCLASSNAME,
NULL,
WS_VISIBLE |
WS_BORDER |
WS_OVERLAPPED |
WS_CHILD |
WS_CLIPCHILDREN |
WS_CLIPSIBLINGS |
RBS_VARHEIGHT |
RBS_BANDBORDERS |
RBS_DBLCLKTOGGLE |
RBS_AUTOSIZE |
RBS_REGISTERDROP |
CCS_TOP |
CCS_NODIVIDER |
CCS_NOPARENTALIGN |
0,
0,
0,
200,
m_info.cyTB,
hwndParent,
(HMENU)IDC_REBAR,
g_hInst,
NULL);
if(!hwndRebar)
return FALSE;
rbi.cbSize = sizeof(rbi);
rbi.fMask = RBIM_IMAGELIST;
rbi.himl = NULL;
if(!SendMessage(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rbi))
return FALSE;
//add a band that contains a button
hwndChild = CreateMainToolbar(hwndRebar);
if(!hwndChild)
return FALSE;
GetClientRect(hwndChild, &rc);
ZeroMemory(&rbbi, sizeof(rbbi));
rbbi.cbSize = sizeof(REBARBANDINFO);
rbbi.fMask = RBBIM_SIZE |
RBBIM_CHILD |
RBBIM_CHILDSIZE |
RBBIM_ID |
RBBIM_STYLE |
0;
rbbi.cxMinChild = rc.right;
rbbi.cyMinChild = MYICON_CY + EXTRA_PIXELS;
rbbi.cyMaxChild = TallestBtn(hwndChild);
rbbi.cyChild = m_info.fTextLabels ? rbbi.cyMaxChild : rbbi.cyMinChild;
rbbi.cyIntegral = rbbi.cyMaxChild - rbbi.cyMinChild;
rbbi.cx = 100;
rbbi.fStyle = RBBS_CHILDEDGE |
RBBS_VARIABLEHEIGHT |
((m_info.windows & WND_TOOLBAR) ? 0 : RBBS_HIDDEN) |
0;
rbbi.wID = IDC_TOOLBAR;
rbbi.hwndChild = hwndChild;
// SendMessage FAILED on visual studio 2010. But worked on visual studio 6.
if(!SendMessage(hwndRebar, RB_INSERTBAND, (WPARAM)-1, (LPARAM)(LPREBARBANDINFO)&rbbi))
{
int i = GetLastError(); // --> i = 6 (invalid handle)
return FALSE;
}
I have try run the code in both visual studio 6 and 2010 and make some comparison. I found that on visual 6, the value of sizeof(REBARBANDINFO) is 80 and on visual studio 2010 it is 100. So I did tried an experiment by hard code value on visual studio 2010 to 80. Then sendMessage was successful but the UI inside that rebar is not visible on window. Can anyone please help me with this problem? Thank you in advance.
EDIT:
Is it a good idea if i replaced sizeof(REBARBANDINFO) with REBARBANDINFOW_V6_SIZE instead of hard-coding value 80?