15,980
社区成员




void CMFCToolBar::AdjustSize();
void CMFCToolBar::AdjustLocations();
nIndex = m_wndToolBar.CommandToIndex(ID_OBJECT_TESTTIME);
if (nIndex >= 0)
{
m_wndToolBar.SetToolBarBtnText(nIndex, strTimeInfo, TRUE, TRUE);
}
m_wndToolBar.AdjustLayout();
CTestProgressToolBar m_wndToolBar;//这个在我的类里面
class CTestProgressToolBar : public CMFCToolBar
{
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
CMFCToolBar::OnUpdateCmdUI((CFrameWnd*) GetOwner(), bDisableIfNoHndler);
}
virtual BOOL AllowShowOnList() const { return FALSE; }
}
// 加载工具栏:
m_wndToolBar.Create(this,
WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_FLOATING,
IDR_TOOLBAR_TMSSVIEW);
m_wndToolBar.LoadToolBar(IDR_TOOLBAR_TMSSVIEW, 0, IDR_TOOLBAR_TMSSVIEW, TRUE, 0, 0, IDR_TOOLBAR_TMSSVIEW);
//nIndex = m_wndToolBar.CommandToIndex(ID_OBJECT_TESTTIME);
// if (nIndex >= 0)
// {
// m_wndToolBar.SetToolBarBtnText(nIndex, strTimeInfo, TRUE, TRUE);
// }
m_wndToolBar.AdjustLayout();
class CTestProgressToolBar : public CMFCToolBar
{
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
CMFCToolBar::OnUpdateCmdUI((CFrameWnd*) GetOwner(), bDisableIfNoHndler);
}
virtual BOOL AllowShowOnList() const { return FALSE; }
public:
virtual void AdjustLayout()
{
if (GetSafeHwnd() == NULL)
{
return;
}
BOOL bHorz = GetCurrentAlignment() & CBRS_ORIENT_HORZ ? TRUE : FALSE;
for (POSITION pos = m_Buttons.GetHeadPosition(); pos != NULL;)
{
CMFCToolBarButton* pButton = (CMFCToolBarButton*) m_Buttons.GetNext(pos);
if (pButton == NULL)
{
break;
}
ASSERT_VALID(pButton);
pButton->m_bTextBelow = ((pButton->m_nStyle & TBBS_SEPARATOR) == 0) && m_bTextLabels && bHorz;
}
CMFCReBar* pBar = DYNAMIC_DOWNCAST(CMFCReBar, GetParent());
if (pBar != NULL)
{
CReBarCtrl& wndReBar = pBar->GetReBarCtrl();
UINT uiReBarsCount = wndReBar.GetBandCount();
REBARBANDINFO bandInfo;
bandInfo.cbSize = pBar->GetReBarBandInfoSize ();
bandInfo.fMask = (RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_IDEALSIZE);
UINT uiBand = 0;
for (uiBand = 0; uiBand < uiReBarsCount; uiBand ++)
{
wndReBar.GetBandInfo(uiBand, &bandInfo);
if (bandInfo.hwndChild == GetSafeHwnd())
{
break;
}
}
bandInfo.fMask ^= RBBIM_CHILD;
if (uiBand >= uiReBarsCount)
{
ASSERT(FALSE);
}
else
{
CSize size = CMFCBaseToolBar::CalcFixedLayout(FALSE, TRUE);
m_nMaxBtnHeight = CalcMaxButtonHeight();
CSize sizeMin = CalcSize(FALSE);
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, TRUE);
sizeMin.cy -= rect.Height();
sizeMin.cx -= rect.Width();
sizeMin.cx = max(sizeMin.cx, size.cx);
sizeMin.cy = max(sizeMin.cy, size.cy);
bandInfo.cxMinChild = m_sizeButton.cx;
bandInfo.cyMinChild = sizeMin.cy;
bandInfo.cxIdeal = sizeMin.cx;
wndReBar.SetBandInfo(uiBand, &bandInfo);
}
}
else
{
//AdjustSize();//+有内存泄露
}
//AdjustLocations();//+++ 有严重内存泄露
RedrawWindow(NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
}
virtual void AdjustSize()
{
CFrameWnd* pParent = AFXGetParentFrame(this);
if (pParent != NULL && pParent->GetSafeHwnd() != NULL)
{
BOOL bMode = (m_pParentDockBar == NULL);
CSize sizeCurr = CalcFixedLayout(bMode, IsHorizontal());
if (sizeCurr.cx == 32767 || sizeCurr.cy == 32767)
{
CRect rectParent;
GetParent()->GetClientRect(&rectParent);
if (sizeCurr.cx == 32767)
{
sizeCurr.cx = rectParent.Width();
if (m_nMaxLen != 0)
{
sizeCurr.cx = min(sizeCurr.cx, m_nMaxLen);
}
}
else
{
sizeCurr.cy = rectParent.Height();
if (m_nMaxLen != 0)
{
sizeCurr.cy = min(sizeCurr.cy, m_nMaxLen);
}
}
}
CRect rect;
GetWindowRect(rect);
CMFCTabCtrl* pTab = DYNAMIC_DOWNCAST(CMFCTabCtrl, GetParent());
if (pTab != NULL)
{
CRect rectWndArea;
pTab->GetWndArea(rectWndArea);
SetWindowPos(NULL, -1, -1, rectWndArea.Width(), rectWndArea.Height(), SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
}
else
{
if (IsCustomizeMode())
{
if (rect.Height() != sizeCurr.cy && sizeCurr.cy != 32767 && IsHorizontal() ||
rect.Width() != sizeCurr.cx && sizeCurr.cx != 32767 && !IsHorizontal())
{
SetWindowPos(NULL, 0, 0, sizeCurr.cx, sizeCurr.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
UpdateVirtualRect();
}
}
else
{
if (rect.Height() != sizeCurr.cy && sizeCurr.cy != 32767 && IsHorizontal() ||
rect.Width() != sizeCurr.cx && sizeCurr.cx != 32767 && !IsHorizontal())
{
CSize sizeMin;
GetMinSize(sizeMin);
int nNewWidth = max(sizeMin.cx, sizeCurr.cx);
int nNewHeight = max(sizeMin.cy, sizeCurr.cy);
SetWindowPos(NULL, 0, 0, nNewWidth, nNewHeight, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
UpdateVirtualRect();
}
}
}
if (!IsFloating() && IsVisible() && m_pParentDockBar != NULL && m_pDockBarRow != NULL)
{
CRect rectWnd;
BOOL bIsHorz = IsHorizontal();
BOOL bResize = FALSE;
m_pDockBarRow->GetClientRect(rectWnd);
if (rectWnd.Height() != sizeCurr.cy && bIsHorz)
{
rectWnd.bottom = rectWnd.top + sizeCurr.cy;
bResize = TRUE;
}
else if (rectWnd.Width() != sizeCurr.cx && !bIsHorz)
{
rectWnd.right = rectWnd.left + sizeCurr.cx;
bResize = TRUE;
}
if (bResize)
{
m_pParentDockBar->ResizeRow(m_pDockBarRow, bIsHorz ? sizeCurr.cy : sizeCurr.cx);
}
if (IsCustomizeMode())
{
UpdateVirtualRect(sizeCurr);
m_pDockBarRow->ArrangePanes(this);
}
pParent->RecalcLayout();
}
else
{
CPaneFrameWnd* pParentMiniFrame = GetParentMiniFrame();
if (pParentMiniFrame != NULL && GetParent() == pParentMiniFrame)
{
pParentMiniFrame->SizeToContent();
pParentMiniFrame->RedrawWindow();
}
else if (!IsKindOf(RUNTIME_CLASS(CMFCDropDownToolBar)))
{
pParent->RecalcLayout(); //这里有内存泄露
}
}
}
}
};