MFC教程(13)-MFC工具条和状态栏(1)
2007-10-04 20:11:24 来源:WEB开发网核心提示:CWnd的成员函数RepositionBarsRepositionBars的实现如下:void CWnd::RepositionBars(UINT nIDFirst, UINT nIDLast, UINT nIDLeftOver,UINT nFlags, LPRECT lpRectParam, LPCRECT lpRe
CWnd的成员函数RepositionBars
RepositionBars的实现如下:
void CWnd::RepositionBars(UINT nIDFirst, UINT nIDLast, UINT nIDLeftOver,
UINT nFlags, LPRECT lpRectParam, LPCRECT lpRectClient, BOOL bStretch)
{
ASSERT(nFlags == 0 || nFlags == reposQuery || nFlags == reposExtra);
AFX_SIZEPARENTPARAMS layout;
HWND hWndLeftOver = NULL;
layout.bStretch = bStretch;
layout.sizeTotal.cx = layout.sizeTotal.cy = 0;
if (lpRectClient != NULL)
layout.rect = *lpRectClient; //从参数6得到客户区
else
//参数lpRectClient空,得到客户区域
GetClientRect(&layout.rect);
if (nFlags != reposQuery)
//准备放置各个子窗口(layout)
layout.hDWP = ::BeginDeferWindowPos(8); // reasonable guess
else
layout.hDWP = NULL; // not actually doing layout
//按一定顺序给各个控制条发送父窗口resize的消息;
//各个控制条窗口收到消息后,从客户区中扣除自己使用的区域;
//并且必要的话每个控制窗口调用::DeferWindowPos
//剩下的区域留给nIDLeftOver子窗口
for (HWND hWndChild = ::GetTopWindow(m_hWnd); hWndChild != NULL;
hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT))
{
UINT nIDC = _AfxGetDlgCtrlID(hWndChild);
CWnd* pWnd = CWnd::FromHandlePermanent(hWndChild);
//如果是指定的nIDLeftOver子窗口,则保存其窗口句柄;
//否则,是控制条窗口,给它们发送WM_SIZEPARENT消息
if (nIDC == nIDLeftOver)
hWndLeftOver = hWndChild;
else if (nIDC >= nIDFirst && nIDC <= nIDLast && pWnd != NULL)
//如果layout->hDWP非空, OnSizeParent则将执行窗口布置的操作
::SendMessage(hWndChild, WM_SIZEPARENT, 0, (LPARAM)&layout);
}
//如果是reposQuery,则得到客户区矩形,返回
if (nFlags == reposQuery)
{
ASSERT(lpRectParam != NULL);
if (bStretch)
::CopyRect(lpRectParam, &layout.rect);
else
{
lpRectParam->left = lpRectParam->top = 0;
lpRectParam->right = layout.sizeTotal.cx;
lpRectParam->bottom = layout.sizeTotal.cy;
}
return;
}
//其他情况下(reposDefault、reposExtra),则需要执行Layout操作
//处理hWndLeftOver(nIDLeftOver子窗口)
if (nIDLeftOver != 0 && hWndLeftOver != NULL)
{
CWnd* pLeftOver = CWnd::FromHandle(hWndLeftOver);
// allow extra space as specified by lpRectBorder
if (nFlags == reposExtra)
{
ASSERT(lpRectParam != NULL);
layout.rect.left += lpRectParam->left;
layout.rect.top += lpRectParam->top;
layout.rect.right -= lpRectParam->right;
layout.rect.bottom -= lpRectParam->bottom;
}
//基于layout.rect表示的客户尺寸计算出窗口尺寸
pLeftOver->CalcWindowRect(&layout.rect);
//导致函数::DeferWindowPos的调用
AfxRepositionWindow(&layout, hWndLeftOver, &layout.rect);
}
//给所有的窗口设置尺寸、位置(size and layout)
if (layout.hDWP == NULL || !::EndDeferWindowPos(layout.hDWP))
TRACE0("Warning: DeferWindowPos failed - low system resources.
");
}
RepositionBars用来改变客户窗口中控制条的尺寸大小或者位置,其中:
更多精彩
赞助商链接