BUG: Resizing CToolbar with Dropdown Arrow Buttons Freezes AppsID: Q190501
|
Resizing a toolbar (CToolBar class) with drop-down arrow buttons causes an infinite loop.
The application is looping in CToolBar::SizeToolBar() because neither sizeMin.cx nor sizeMax.cx changes its value. In other words, in CToolBar::SizeToolBar(), the loop hangs on the case where sizeMax == sizeMid.
Because CToolBar::SizeToolBar() is not a virtual function, we need to
reimplement this function and override the virtual functions in CToolBar
class to call our SizeToolBar() function.
Below are the steps to correct this problem:
void CMyToolBar::_GetButton(int nIndex, TBBUTTON* pButton) const
{
CMyToolBar* pBar = (CMyToolBar*) this;
VERIFY(pBar->DefWindowProc(TB_GETBUTTON, nIndex,
(LPARAM)pButton));
// TBSTATE_ENABLED == TBBS_DISABLED so invert it.
pButton->fsState ^= TBSTATE_ENABLED;
}
while (sizeMin.cx < sizeMax.cx)
{
sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
WrapToolBar(pData, nCount, sizeMid.cx);
sizeMid = CalcSize(pData, nCount);
if (nLength < sizeMid.cy)
{
if (sizeMin == sizeMid)
{
WrapToolBar(pData, nCount, sizeMax.cx);
return;
}
sizeMin = sizeMid;
}
else if (nLength > sizeMid.cy && sizeMax != sizeMid)
sizeMax = sizeMid;
else
return;
}
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
In CToolBar::SizeToolBar(), the loop hangs on the case where sizeMax == sizeMid:
while (sizeMin.cx < sizeMax.cx)
{
sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
WrapToolBar(pData, nCount, sizeMid.cx);
sizeMid = CalcSize(pData, nCount);
if (nLength < sizeMid.cy)
{
if (sizeMin == sizeMid)
{
WrapToolBar(pData, nCount, sizeMax.cx);
return;
}
sizeMin = sizeMid;
}
else if (nLength > sizeMid.cy)
sizeMax = sizeMid;
else
return;
}
// Set the drop-down buttons to have the appropriate styles.
CToolBarCtrl& rCtrl = m_wndToolBar.GetToolBarCtrl();
TBBUTTONINFO tbbi;
tbbi.dwMask = TBIF_STYLE;
tbbi.cbSize = sizeof tbbi;
rCtrl.GetButtonInfo(ID_FILE_OPEN, &tbbi);
tbbi.fsStyle |= TBSTYLE_DROPDOWN;
VERIFY(rCtrl.SetButtonInfo(ID_FILE_OPEN, &tbbi));
rCtrl.SetExtendedStyle(
rCtrl.GetExtendedStyle() | TBSTYLE_EX_DRAWDDARROWS);
© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Yeong-Kah Tam, Microsoft Corporation
Additional query words: kbvc600bug
Keywords : kbVC600bug
Version : WINNT:6.0
Platform : winnt
Issue type : kbbug
Last Reviewed: August 5, 1999