我正在尝试将 Visual Studio 6 上完全正常工作的 Win32 代码迁移到 Visual Studio 2010。Rebar 似乎存在一些问题。以下是我在 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;
}
我尝试在 Visual Studio 6 和 2010 中运行代码并进行一些比较。我发现在视觉 6 上,sizeof(REBARBANDINFO)的值是80而在视觉工作室 2010 上它是100。所以我确实在visual studio 2010上通过硬编码值尝试了一个实验到80。然后sendMessage成功了,但是那个钢筋里面的UI在窗口上是不可见的。谁能帮我解决这个问题?先感谢您。
编辑:
如果我用REBARBANDINFOW_V6_SIZE而不是硬编码值 80替换sizeof(REBARBANDINFO)是个好主意吗?