Wednesday, March 02, 2005

 

Some notes on StatusBar

1.
How to get correct rect size of each pane

below are some codes from my friend

CRect rcClient;
GetClientRect(&rcClient);

int cx = ::GetSystemMetrics(SM_CXEDGE);

int i;
for (i = 0; i < m_arControls.GetSize(); i++ )
{
int iIndex = CommandToIndex(m_arControls[i]->nID);
DWORD dwStyle = GetPaneStyle(iIndex);
CWnd* pWnd = m_arControls[i]->pWnd;

CRect rcPane;
GetItemRect(iIndex, &rcPane);

// WINBUG: CStatusBar::GetItemRect(...) does not return the correct size
// of the last item in the status bar in most cases, so we need to calculate
// the width ourself...

if (iIndex == (m_nCount-1))
{
if ((dwStyle & SBPS_STRETCH ) == 0)
{
UINT nID;
UINT nStyle;
int cxWidth;
GetPaneInfo(iIndex, nID, nStyle, cxWidth);

rcPane.right = rcPane.left + cxWidth + (cx*3);
}
else
{
rcPane.right = rcClient.right;

if ((GetStyle() & SBARS_SIZEGRIP) == SBARS_SIZEGRIP) {
rcPane.right -= (Icon.width() + cx);
}
}
}

if ((GetPaneStyle (iIndex) & SBPS_NOBORDERS) == 0) {
rcPane.DeflateRect(cx,cx);
}

if (pWnd && ::IsWindow(pWnd->m_hWnd))
pWnd->MoveWindow(rcPane);
}

It should be pointed out that this bug first emerges as I transfered codes from Windows 2000 to XP.

2.
Check on OnIdleUpdateCmdUI

I get this code segment from my friend, too.

// handle delay hide/show
BOOL bVis = GetStyle() & WS_VISIBLE;
UINT swpFlags = 0;
if ((m_nStateFlags & delayHide) && bVis)
swpFlags = SWP_HIDEWINDOW;
else if ((m_nStateFlags & delayShow) && !bVis)
swpFlags = SWP_SHOWWINDOW;
m_nStateFlags &= ~(delayShow|delayHide);
if (swpFlags != 0)
{
SetWindowPos(NULL, 0, 0, 0, 0, swpFlags|
SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
}

// the style must be visible and if it is docked
// the dockbar style must also be visible
if ((GetStyle() & WS_VISIBLE) &&
(m_pDockBar == NULL || (m_pDockBar->GetStyle() & WS_VISIBLE)))
{
// MFCBUG: removed check for IsFrameWnd so we can update statusbar
// for dialog based applications as well as doc/view apps.
CFrameWnd* pTarget = (CFrameWnd*)GetOwner();
if (pTarget == NULL)
pTarget = (CFrameWnd*)GetParent();
if (pTarget != NULL)
OnUpdateCmdUI(pTarget, (BOOL)wParam);
}
return 0L;

I was once burned by these two problems intensively.



<< Home

This page is powered by Blogger. Isn't yours?