LRESULT CControlBar::OnSizeParent( WPARAM wParam, LPARAM lParam ) /***************************************************************/ { UNUSED_ALWAYS( wParam ); if( GetStyle() & WS_VISIBLE ) { AFX_SIZEPARENTPARAMS *pSPP = (AFX_SIZEPARENTPARAMS *)lParam; ASSERT( pSPP != NULL ); DWORD nMode = 0L; if( m_dwStyle & CBRS_ORIENT_HORZ ) { nMode |= LM_HORZ; } if( pSPP->bStretch ) { nMode |= LM_STRETCH; } CSize size = CalcDynamicLayout( -1, nMode ); CRect rect; if( m_dwStyle & CBRS_ALIGN_LEFT ) { rect.left = pSPP->rect.left; rect.top = pSPP->rect.top; rect.right = pSPP->rect.left + size.cx; rect.bottom = min( pSPP->rect.top + size.cy, pSPP->rect.bottom ); pSPP->rect.left += size.cx; pSPP->sizeTotal.cx += size.cx; pSPP->sizeTotal.cy = max( pSPP->sizeTotal.cy, size.cy ); } else if( m_dwStyle & CBRS_ALIGN_RIGHT ) { rect.left = pSPP->rect.right - size.cx; rect.top = pSPP->rect.top; rect.right = pSPP->rect.right; rect.bottom = min( pSPP->rect.top + size.cy, pSPP->rect.bottom ); pSPP->rect.right -= size.cx; pSPP->sizeTotal.cx += size.cx; pSPP->sizeTotal.cy = max( pSPP->sizeTotal.cy, size.cy ); } else if( m_dwStyle & CBRS_ALIGN_BOTTOM ) { rect.left = pSPP->rect.left; rect.top = pSPP->rect.bottom - size.cy; rect.right = min( pSPP->rect.left + size.cx, pSPP->rect.right ); rect.bottom = pSPP->rect.bottom; pSPP->rect.bottom -= size.cy; pSPP->sizeTotal.cx = max( pSPP->sizeTotal.cx, size.cx ); pSPP->sizeTotal.cy += size.cy; } else { rect.left = pSPP->rect.left; rect.top = pSPP->rect.top; rect.right = min( pSPP->rect.left + size.cx, pSPP->rect.right ); rect.bottom = pSPP->rect.top + size.cy; pSPP->rect.top += size.cy; pSPP->sizeTotal.cx = max( pSPP->sizeTotal.cx, size.cx ); pSPP->sizeTotal.cy += size.cy; } AfxRepositionWindow( pSPP, m_hWnd, &rect ); } return( 0L ); }
void CCustomToolBar::OnPaint() { ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Copied from CToolBar::OnPaint() if (m_bDelayedButtonLayout) { m_bDelayedButtonLayout = FALSE; BOOL bHorz = (m_dwStyle & CBRS_ORIENT_HORZ) != 0; if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC)) CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT); else if (bHorz) CalcDynamicLayout(0, LM_HORZ | LM_HORZDOCK | LM_COMMIT); else CalcDynamicLayout(0, LM_VERTDOCK | LM_COMMIT); } ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // Get the rectangle we're going to be drawing. CRect crUpdate; if (GetUpdateRect(crUpdate)) { // Get the actual device context we will be painting onto. CPaintDC dc(this); // Select out palette into the DC. CPalette* pOldPalette; SelectPalette(dc, pOldPalette, FALSE); // We construct an offscreen bitmap with the contents // to copy onto the final DC. This should avoid all flicker. // Create a DC for the offscreen bitmap. CDC dcOffScreen; if (dcOffScreen.CreateCompatibleDC(&dc)) { // Create the offscreen bitmap in a format compatible // with the destination DC. CBitmap OffScreenBitmap; if (OffScreenBitmap.CreateCompatibleBitmap(&dc, crUpdate.Width(), crUpdate.Height())) { // Select our palette into the offscreen DC. CPalette* pOldOffScreenPalette; SelectPalette(dcOffScreen, pOldOffScreenPalette, TRUE); // Select the bitmap into the DC. CBitmap* pOldBitmap = dcOffScreen.SelectObject(&OffScreenBitmap); if (pOldBitmap != NULL) { // Offset the origin of the offscreen DC to match // the coordinate system of the final destination DC. dcOffScreen.OffsetWindowOrg(crUpdate.left, crUpdate.top); // Draw the background (DrawBackground() is virtual.) DrawBackground(dcOffScreen, crUpdate, CSize(0,0)); int nButtons = GetToolBarCtrl().GetButtonCount(); for (int nButton = 0; nButton < nButtons; nButton++) { // Get the bounding rectangle of the button. CRect crButton; GetItemRect(nButton, crButton); // Check if the button is in the update region. If not, then // there's nothing to draw. CRect crIntersect; if (crIntersect.IntersectRect(crButton, crUpdate)) { // Get the button information. UINT uButtonID; UINT uButtonStyleState; int nButtonBitmap; GetButtonInfo(nButton, uButtonID, uButtonStyleState, nButtonBitmap); WORD wButtonStyle = LOWORD(uButtonStyleState); WORD wButtonState = HIWORD(uButtonStyleState); // If the button is hidden, then there's nothing to draw. if ((wButtonState & TBSTATE_HIDDEN) == 0) { if (wButtonStyle == TBSTYLE_SEP) { // Draw the separator (DrawSeparator() is virtual.) DrawSeparator(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState); } else { // Draw the button (DrawButton() is virtual.) DrawButton(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState); } } } } // Copy the offscreen bitmap to the destination DC. dc.BitBlt( crUpdate.left, crUpdate.top, crUpdate.Width(), crUpdate.Height(), &dcOffScreen, crUpdate.left, crUpdate.top, SRCCOPY); dcOffScreen.SelectObject(pOldBitmap); pOldBitmap = NULL; } // Clean up the offscreen bitmap and DC. OffScreenBitmap.DeleteObject(); DeselectPalette(dcOffScreen, pOldOffScreenPalette, TRUE); } dcOffScreen.DeleteDC(); } DeselectPalette(dc, pOldPalette, FALSE); } }
LRESULT CXTPDockBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = GetStyle(); if (dwStyle & WS_VISIBLE) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size DWORD dwMode = lpLayout->bStretch ? LM_STRETCH : 0; if ((m_dwStyle & CBRS_SIZE_DYNAMIC) && m_dwStyle & CBRS_FLOATING) dwMode |= LM_HORZ | LM_MRUWIDTH; else if (dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; int nLength = (dwStyle & CBRS_ORIENT_HORZ ? sizeAvail.cx : sizeAvail.cy) /*- 2 * GetSystemMetrics(SM_CXBORDER)*/; CSize size = CalcDynamicLayout(nLength, dwMode, lpLayout); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); Invalidate(FALSE); } return 0; }
LRESULT CControlBar::OnSizeParent(WPARAM, LPARAM lParam) { AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam; DWORD dwStyle = RecalcDelayShow(lpLayout); if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0) { // align the control bar CRect rect; rect.CopyRect(&lpLayout->rect); CSize sizeAvail = rect.Size(); // maximum size available // get maximum requested size DWORD dwMode = lpLayout->bStretch ? LM_STRETCH : 0; if ((m_dwStyle & CBRS_SIZE_DYNAMIC) && m_dwStyle & CBRS_FLOATING) dwMode |= LM_HORZ | LM_MRUWIDTH; else if (dwStyle & CBRS_ORIENT_HORZ) dwMode |= LM_HORZ | LM_HORZDOCK; else dwMode |= LM_VERTDOCK; CSize size = CalcDynamicLayout(-1, dwMode); size.cx = min(size.cx, sizeAvail.cx); size.cy = min(size.cy, sizeAvail.cy); if (dwStyle & CBRS_ORIENT_HORZ) { lpLayout->sizeTotal.cy += size.cy; lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx); if (dwStyle & CBRS_ALIGN_TOP) lpLayout->rect.top += size.cy; else if (dwStyle & CBRS_ALIGN_BOTTOM) { rect.top = rect.bottom - size.cy; lpLayout->rect.bottom -= size.cy; } } else if (dwStyle & CBRS_ORIENT_VERT) { lpLayout->sizeTotal.cx += size.cx; lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy); if (dwStyle & CBRS_ALIGN_LEFT) lpLayout->rect.left += size.cx; else if (dwStyle & CBRS_ALIGN_RIGHT) { rect.left = rect.right - size.cx; lpLayout->rect.right -= size.cx; } } else { ASSERT(FALSE); // can never happen } rect.right = rect.left + size.cx; rect.bottom = rect.top + size.cy; // only resize the window if doing layout and not just rect query if (lpLayout->hDWP != NULL) AfxRepositionWindow(lpLayout, m_hWnd, &rect); } return 0; }
LRESULT CToolbarControlBar::OnSizeParent(WPARAM wParam, LPARAM lParam) { m_sizeFixedLayout = CalcDynamicLayout(0, 0); return CControlBar::OnSizeParent(wParam, lParam); }