void CScrollWnd::ResizeParentToFit(BOOL bShrinkOnly) { // adjust parent rect so client rect is appropriate size ASSERT(m_nMapMode != MM_NONE); // mapping mode must be known // determine current size of the client area as if no scrollbars present CRect rectClient; GetWindowRect(rectClient); CRect rect = rectClient; CalcWindowRect(rect); rectClient.left += rectClient.left - rect.left; rectClient.top += rectClient.top - rect.top; rectClient.right -= rect.right - rectClient.right; rectClient.bottom -= rect.bottom - rectClient.bottom; rectClient.OffsetRect(-rectClient.left, -rectClient.top); ASSERT(rectClient.left == 0 && rectClient.top == 0); // determine desired size of the Wnd CRect rectWnd(0, 0, m_totalDev.cx, m_totalDev.cy); if (bShrinkOnly) { if (rectClient.right <= m_totalDev.cx) rectWnd.right = rectClient.right; if (rectClient.bottom <= m_totalDev.cy) rectWnd.bottom = rectClient.bottom; } CalcWindowRect(rectWnd, CWnd::adjustOutside); rectWnd.OffsetRect(-rectWnd.left, -rectWnd.top); ASSERT(rectWnd.left == 0 && rectWnd.top == 0); if (bShrinkOnly) { if (rectClient.right <= m_totalDev.cx) rectWnd.right = rectClient.right; if (rectClient.bottom <= m_totalDev.cy) rectWnd.bottom = rectClient.bottom; } // dermine and set size of frame based on desired size of Wnd CRect rectFrame; CFrameWnd* pFrame = GetParentFrame(); ASSERT_VALID(pFrame); pFrame->GetWindowRect(rectFrame); CSize size = rectFrame.Size(); size.cx += rectWnd.right - rectClient.right; size.cy += rectWnd.bottom - rectClient.bottom; pFrame->SetWindowPos(NULL, 0, 0, size.cx, size.cy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); }
BOOL COXMonthCalCtrl::SetCtrlDimension(int nXDimension, int nYDimension, const CSize& szMargins/*=CSize(0,0)*/) { ASSERT(::IsWindow(m_hWnd)); if(nXDimension*nYDimension>ID_MAXMONTHCOUNT) { TRACE(_T("COXMonthCalCtrl::SetCtrlDimension: The maximum total number of displayed months is %d\n"),ID_MAXMONTHCOUNT); return FALSE; } CRect rect; GetWindowRect(rect); CPoint ptTopLeft=rect.TopLeft(); CWnd* pWnd=GetParent(); if(pWnd!=NULL) { ASSERT(::IsWindow(pWnd->GetSafeHwnd())); pWnd->ScreenToClient(&ptTopLeft); } BOOL bResult=FALSE; if(GetReqRect(rect,nXDimension,nYDimension)) { rect.right+=szMargins.cx*2; rect.bottom+=szMargins.cy*2; CalcWindowRect(rect); if(SetWindowPos(NULL,ptTopLeft.x,ptTopLeft.y,rect.Width(),rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE)) bResult=TRUE; } return bResult; }
bool CGameApp::InitMode(bool bFullScreen, int nWidth, int nHeight) { if(m_hWnd) { DestroyWindow(); m_hWnd = NULL; } m_nWidth = nWidth; m_nHeight = nHeight; DWORD dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW; //DWORD dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP; DWORD dwExStyle = 0; CRect rect(0, 0, GetWidth(), GetHeight()); if(!CreateEx(m_hInstance, m_szAppName, m_szAppName, dwExStyle, dwStyle, &rect)) { MessageBox("Unable to create application window, aborting."); return false; } CalcWindowRect(&rect); MoveWindow(0, 0, rect.Width(), rect.Height(), false); ShowWindow(m_nShowCmd); UpdateWindow(); return true; }
LRESULT AFX_TOOLTIP::OnSetText(WPARAM, LPARAM lParam) { Default(); LPTSTR lpsz = (LPTSTR)lParam; ASSERT(lpsz != NULL); // size window to fit text CClientDC dc(NULL); HFONT hFontOld = NULL; if (afxData.hToolTipsFont != NULL) hFontOld = (HFONT)dc.SelectObject(afxData.hToolTipsFont); CSize size = dc.GetTextExtent(lpsz, lstrlen(lpsz)); CRect rect(0, 0, size.cx, size.cy); CalcWindowRect(&rect); TCHAR chSpace = ' '; size = dc.GetTextExtent(&chSpace, 1); if (hFontOld != NULL) dc.SelectObject(hFontOld); // add a little extra space to left, right, top, and bottom rect.InflateRect(size.cx, CY_BORDER); SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); return TRUE; }
int CShapePropSheetFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CMiniFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; m_pModelessShapePropSheet = new CModelessShapePropSheet(this); if (!m_pModelessShapePropSheet->Create(this, WS_CHILD | WS_VISIBLE, 0)) { delete m_pModelessShapePropSheet; m_pModelessShapePropSheet = NULL; return -1; } // Resize the mini frame so that it fits around the child property // sheet. CRect rectClient, rectWindow; m_pModelessShapePropSheet->GetWindowRect(rectClient); rectWindow = rectClient; // CMiniFrameWnd::CalcWindowRect adds the extra width and height // needed from the mini frame. CalcWindowRect(rectWindow); SetWindowPos(NULL, rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(), SWP_NOZORDER | SWP_NOACTIVATE); m_pModelessShapePropSheet->SetWindowPos(NULL, 0, 0, rectClient.Width(), rectClient.Height(), SWP_NOZORDER | SWP_NOACTIVATE); return 0; }
void CMyView::ResizeParentToFit(const SIZE& desired_size, BOOL bShrinkOnly) { // determine current size of the client area as if no scrollbars present CRect rectClient; GetWindowRect(rectClient); CRect rect = rectClient; CalcWindowRect(rect); rectClient.left += rectClient.left - rect.left; rectClient.top += rectClient.top - rect.top; rectClient.right -= rect.right - rectClient.right; rectClient.bottom -= rect.bottom - rectClient.bottom; rectClient.OffsetRect(-rectClient.left, -rectClient.top); ASSERT(rectClient.left == 0 && rectClient.top == 0); // determine desired size of the view CRect rectView(0, 0, desired_size.cx, desired_size.cy); if (bShrinkOnly) { if (rectClient.right <= desired_size.cx) rectView.right = rectClient.right; if (rectClient.bottom <= desired_size.cy) rectView.bottom = rectClient.bottom; } CalcWindowRect(rectView, CWnd::adjustOutside); rectView.OffsetRect(-rectView.left, -rectView.top); ASSERT(rectView.left == 0 && rectView.top == 0); if (bShrinkOnly) { if (rectClient.right <= desired_size.cx) rectView.right = rectClient.right; if (rectClient.bottom <= desired_size.cy) rectView.bottom = rectClient.bottom; } // dermine and set size of frame based on desired size of view CRect rectFrame; CFrameWnd* pFrame = GetParentFrame(); ASSERT_VALID(pFrame); pFrame->GetWindowRect(rectFrame); CSize size = rectFrame.Size(); size.cx += rectView.right - rectClient.right; size.cy += rectView.bottom - rectClient.bottom; pFrame->SetWindowPos(NULL, 0, 0, size.cx, size.cy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); }
BOOL CSettingsSheet::SkinMe(LPCTSTR pszSkin, UINT nIcon, BOOL bLanguage) { EnableBanner( FALSE ); m_szPages.cx = m_szPages.cy = 0; for ( int nPage = 0 ; nPage < GetPageCount() ; nPage++ ) { CSettingsPage* pPage = GetPage( nPage ); CDialogTemplate pTemplate; if ( pPage->GetTemplateName() == NULL ) continue; if ( pTemplate.Load( pPage->GetTemplateName() ) ) { CSize size; pTemplate.GetSizeInPixels( &size ); m_szPages.cx = max( m_szPages.cx, size.cx ); m_szPages.cy = max( m_szPages.cy, size.cy ); } } CRect rcWindow( 0, 0, m_szPages.cx + m_nListWidth + m_nListMargin, m_szPages.cy + + m_nButtonHeight + 8 + 8 + 2 ); CalcWindowRect( &rcWindow ); SetWindowPos( &wndTop, 0, 0, rcWindow.Width(), rcWindow.Height(), SWP_NOMOVE|SWP_NOZORDER ); CRect rcTree( 0, 2, m_nListWidth, 2 + m_szPages.cy ); m_wndTree.MoveWindow( &rcTree ); CRect rcButton( 8, 2 + m_szPages.cy + 8, 8 + m_nButtonWidth, 2 + m_szPages.cy + 8 + m_nButtonHeight ); m_wndOK.MoveWindow( &rcButton ); rcButton.OffsetRect( rcButton.Width() + 8, 0 ); m_wndCancel.MoveWindow( &rcButton ); rcButton.OffsetRect( rcButton.Width() + 8, 0 ); m_wndApply.MoveWindow( &rcButton ); CenterWindow(); SetActivePage( m_pPage ? m_pPage : m_pFirst ); return CSkinDialog::SkinMe( pszSkin, nIcon, bLanguage ); }
void CFileManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { // the minimum client rectangle (in that is lying the view window) CRect rt(0, 0, 700, 400); // compute the required size of the frame window rectangle // based on the desired client-rectangle size CalcWindowRect(rt); lpMMI->ptMinTrackSize.x = rt.Width(); lpMMI->ptMinTrackSize.y = rt.Height(); //CDialogEx::OnGetMinMaxInfo(lpMMI); }
Grafik::Grafik(CWnd* pParent /*=NULL*/) : CDialog(IDD_GRAFIK, pParent) { CRect r; Create(IDD_GRAFIK, pParent); r.SetRect(0, 0, minb * 3 / 2, minh * 3 / 2); r.OffsetRect(100, 100); CalcWindowRect(&r, 0); SetWindowText(CString("Grafik: ") + DemoData.get_name()); MoveWindow(&r, TRUE); ShowWindow(SW_SHOW); }
void CSettingsSheet::Layout() { TEXTMETRIC txtMetric; CDC* pDC = GetDC(); pDC->SelectObject( &CoolInterface.m_fntNormal ); pDC->GetTextMetrics( &txtMetric ); ReleaseDC( pDC ); m_nButtonHeight = ( txtMetric.tmHeight + txtMetric.tmExternalLeading ) + 10; m_szPages.cx = m_szPages.cy = 0; for ( int nPage = 0 ; nPage < GetPageCount() ; nPage++ ) { CSettingsPage* pPage = GetPage( nPage ); CDialogTemplate pTemplate; if ( pPage->GetTemplateName() == NULL ) continue; if ( pTemplate.Load( pPage->GetTemplateName() ) ) { CSize size; pTemplate.GetSizeInPixels( &size ); m_szPages.cx = max( m_szPages.cx, size.cx ); m_szPages.cy = max( m_szPages.cy, size.cy ); } } CRect rc( 0, 0, m_szPages.cx, m_szPages.cy ); rc.right += m_nListWidth + m_nListMargin; rc.right += m_nLeftMargin; rc.bottom += m_nTopMargin + m_nButtonHeight + 16; CalcWindowRect( &rc ); SetWindowPos( &wndTop, 0, 0, rc.Width(), rc.Height(), SWP_NOMOVE|SWP_NOZORDER ); rc.SetRect( m_nLeftMargin, m_nTopMargin, 0, 0 ); rc.right = rc.left + m_nListWidth; rc.bottom = rc.top + m_szPages.cy; m_wndTree.MoveWindow( &rc ); rc.SetRect( 8, rc.bottom + 8, 76, m_nButtonHeight ); rc.right += rc.left; rc.bottom += rc.top; m_wndOK.MoveWindow( &rc ); rc.OffsetRect( rc.Width() + 8, 0 ); m_wndCancel.MoveWindow( &rc ); rc.OffsetRect( rc.Width() + 8, 0 ); m_wndApply.MoveWindow( &rc ); }
void COleIPFrameWnd::RecalcLayout(BOOL /*bNotify*/) { ASSERT_VALID(this); // better have a parent window (only used for inplace) CWnd* pParentWnd = GetParent(); ASSERT_VALID(pParentWnd); // first call reposition bars with arbitarily large rect just to // see how much space the bars will take up CRect rectBig(0, 0, INT_MAX/2, INT_MAX/2); CRect rectLeft; RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectLeft, &rectBig); // grow the rect by the size of the control bars CRect rect = m_rectPos; rect.left -= rectLeft.left; rect.top -= rectLeft.top; rect.right += INT_MAX/2 - rectLeft.right; rect.bottom += INT_MAX/2 - rectLeft.bottom; // see how much extra space for non-client areas (such as scrollbars) // that the view needs. CWnd* pLeftOver = GetDlgItem(AFX_IDW_PANE_FIRST); if (pLeftOver != NULL) { rectBig = m_rectPos; pLeftOver->CalcWindowRect(&rectBig, CWnd::adjustOutside); rect.left -= m_rectPos.left - rectBig.left; rect.top -= m_rectPos.top - rectBig.top; rect.right += rectBig.right - m_rectPos.right; rect.bottom += rectBig.bottom - m_rectPos.bottom; } // adjust for non-client area on the frame window CalcWindowRect(&rect, CWnd::adjustOutside); // the frame window must be clipped to the visible part in the container CRect rectVis; rectVis.IntersectRect(&rect, &m_rectClip); // move the window AfxRepositionWindow(NULL, m_hWnd, &rectVis); // now resize the control bars relative to the (now moved) frame pParentWnd->ClientToScreen(&rect); ScreenToClient(&rect); RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, CWnd::reposDefault, NULL, &rect); }
void CRaster::OnGetMinMaxInfo(MINMAXINFO* lpMMI) // REQ #050 { // REQ #050 if(c_Frame.GetSafeHwnd() != NULL) // REQ #050 { /* can limit */ // REQ #050 CRect r; // REQ #050 c_Frame.GetWindowRect(&r); // REQ #050 ScreenToClient(&r); // REQ #050 CalcWindowRect(&r); // REQ #050 lpMMI->ptMinTrackSize.x = r.Width(); // REQ #050 lpMMI->ptMinTrackSize.y = r.Height(); // REQ #050 return; // REQ #050 } /* can limit */ // REQ #050 CFormView::OnGetMinMaxInfo(lpMMI); // REQ #050// REQ #054 } // CRaster::OnGetMinMaxInfo // REQ #050
FW_DropDownWnd::FW_DropDownWnd(CWnd* pParent) : m_nDropDownState(0), m_bMouseTracking(false), m_buttonRect(0,0,0,0) { CString str = AfxRegisterWndClass(CS_DBLCLKS); CreateEx(0,str, _T(""), WS_VISIBLE | WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, pParent->m_hWnd, NULL); CRect rect(0,0,250,100); CalcWindowRect(&rect); SetWindowPos(NULL,200,400,rect.Width(),rect.Height(), SWP_NOZORDER); }
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { CFrameWnd::OnGetMinMaxInfo(lpMMI); if(m_wndCategoryBar.GetSafeHwnd () != NULL) { CRect rtRect (CPoint (0, 0), m_wndCategoryBar.CalcSize (FALSE)); rtRect.bottom = 200; CalcWindowRect (rtRect, CWnd::adjustBorder); lpMMI->ptMinTrackSize.x = rtRect.Width (); lpMMI->ptMinTrackSize.y = rtRect.Height (); } }
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); //获取工具栏高度 CRect rcToolBar; m_wndToolBar.GetWindowRect(&rcToolBar); //获取状态栏高度 CRect rcStatusBar; m_wndStatusBar.GetWindowRect(&rcStatusBar); //设置窗口的大小 CRect rect(0, 0, 32 * GRID_SIZE, 22 * GRID_SIZE + rcToolBar.Height() + rcStatusBar.Height() + GRID_SIZE / 2); CalcWindowRect(&rect); SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOZORDER | SWP_NOREDRAW | SWP_NOMOVE); CenterWindow(); return 0; }
int CNotifyWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // TODO: この位置に固有の作成用コードを追加してください CRect cRect( 0, 0, lpCreateStruct->cx, lpCreateStruct->cy); CString cStrTitle; GetWindowText( cStrTitle); CDC* pcDC = GetDC(); pcDC->DrawText( cStrTitle, cRect, DT_LEFT | DT_CALCRECT | DT_SINGLELINE); ReleaseDC( pcDC); CalcWindowRect( cRect); MoveWindow( cRect); SetTimer( 5500, 500, NULL); return 0; }
CMainWindow::CMainWindow () { CString strWndClass = AfxRegisterWndClass ( 0, myApp.LoadStandardCursor (IDC_ARROW), (HBRUSH) (COLOR_3DFACE + 1), myApp.LoadStandardIcon (IDI_WINLOGO) ); CreateEx (0, strWndClass, _T ("FontView"), WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL); CRect rect (0, 0, m_cxChar * 68, m_cyChar * 26); CalcWindowRect (&rect); SetWindowPos (NULL, 0, 0, rect.Width (), rect.Height (), SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW); }
void CFrameWnd::RecalcLayout( BOOL bNotify ) /******************************************/ { UNUSED_ALWAYS( bNotify ); if( !m_bInRecalcLayout ) { m_bInRecalcLayout = TRUE; if( GetStyle() & FWS_SNAPTOBARS ) { CRect rect; RepositionBars( 0, 0xFFFF, AFX_IDW_PANE_FIRST, reposQuery, &rect, NULL, FALSE ); CalcWindowRect( &rect ); ::SetWindowPos( m_hWnd, NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); } RepositionBars( 0, 0xFFFF, AFX_IDW_PANE_FIRST ); ::UpdateWindow( m_hWnd ); m_bInRecalcLayout = FALSE; } }
void CRuntimeDlg::AutoFit() { // iterate all the child controls accumulating the largest bottom right coord CRect rClient(0, 0, 0, 0); CWnd* pCtrl = GetWindow(GW_CHILD); while (pCtrl) { CRect rCtrl; pCtrl->GetWindowRect(rCtrl); ScreenToClient(rCtrl); rClient.right = max(rClient.right, rCtrl.right); rClient.bottom = max(rClient.bottom, rCtrl.bottom); pCtrl = pCtrl->GetNextWindow(); } // add border rClient.right += m_rBorders.right; rClient.bottom += m_rBorders.bottom; // calc new window rect CRect rWindow; GetWindowRect(rWindow); CalcWindowRect(rClient); rClient = CRect(rWindow.TopLeft(), rClient.Size()); CPoint ptTopLeft = GetInitialPos(); if (ptTopLeft.x != -1 || ptTopLeft.y != -1) rClient.OffsetRect(ptTopLeft - rClient.TopLeft()); else // match centerpoints of old and new rClient.OffsetRect(rWindow.CenterPoint() - rClient.CenterPoint()); MoveWindow(rClient); }
//创建函数 BOOL CPasswordKeyboard::OnInitDialog() { __super::OnInitDialog(); //设置变量 m_bMouseDown=false; m_wHoverRow=INVALID_WORD; m_wHoverLine=INVALID_WORD; //获取状态 m_bShiftStatus=(GetKeyState(VK_SHIFT)&0xF0)>0; m_bCapsLockStatus=(GetKeyState(VK_CAPITAL)&0x0F)>0; //构造位置 CRect rcWindow; rcWindow.SetRect(0,0,m_SizeBackGround.cx,m_SizeBackGround.cy); //移动窗口 CalcWindowRect(&rcWindow,CWnd::adjustBorder); SetWindowPos(NULL,0,0,rcWindow.Width(),rcWindow.Height(),SWP_NOMOVE|SWP_NOZORDER); return FALSE; }
void CToolBarPopup::SetPosition( UINT nFlags, CPoint pt, CRect& rcExclude ) { // The main purpose of this functions is to find proper position of // the popup window, so that we neither exceed screen dimensions nor // intersect rcExclude rectangle. The function also takes into account // control flags specified by the user. // Calc initial position CRect rc; m_tbCtrl.GetWindowRect( rc ); CalcWindowRect( rc, CWnd::adjustBorder ); rc.OffsetRect( -rc.TopLeft() ); rc.OffsetRect( ( nFlags & TPM_CENTERALIGN ) ? ( pt.x - rc.Width() / 2 ) : ( nFlags & TPM_RIGHTALIGN ) ? ( pt.x - rc.Width() ) : pt.x, 0 ); rc.OffsetRect( 0, ( nFlags & TPM_VCENTERALIGN ) ? ( pt.y - rc.Height() / 2 ) : ( nFlags & TPM_BOTTOMALIGN ) ? ( pt.y - rc.Height() ) : pt.y ); // Make sure we don't exceed screen dimensions CRect rcDesktop; GetDesktopWindow()->GetWindowRect( rcDesktop ); rc.OffsetRect( min( rcDesktop.right - rc.right, (LONG)0 ), min( rcDesktop.bottom - rc.bottom, (LONG)0 ) ); rc.OffsetRect( max( rcDesktop.left - rc.left, (LONG)0 ), max( rcDesktop.top - rc.top, (LONG)0 ) ); // Make sure we don't intersect rcExclude rectangle CRect rcTemp; if ( !rcExclude.IsRectEmpty() && rcTemp.IntersectRect( rc, rcExclude ) ) { if ( nFlags & TPM_VERTICAL ) { CRect rcUp( rc ); int nUp = rc.bottom - rcExclude.top; rcUp.OffsetRect( 0, -nUp ); CRect rcDown( rc ); int nDown = rcExclude.bottom - rc.top; rcDown.OffsetRect( 0, nDown ); bool bUp = false; if ( ( rcUp.top >= rcDesktop.top ) && ( rcDown.bottom <= rcDesktop.bottom ) ) { bUp = ( nUp < nDown ); } else if ( rcUp.top >= rcDesktop.top ) { bUp = true; } else if ( rcDown.bottom <= rcDesktop.bottom ) { bUp = false; } else { ASSERT( false ); // this case is not supported yet } rc = bUp ? rcUp : rcDown; nFlags &= ~( TPM_HORPOSANIMATION | TPM_HORNEGANIMATION | TPM_VERPOSANIMATION | TPM_VERNEGANIMATION ); nFlags |= ( bUp ? TPM_VERNEGANIMATION : TPM_VERPOSANIMATION ); } else { CRect rcLeft( rc ); int nLeft = rc.right - rcExclude.left; rcLeft.OffsetRect( -nLeft, 0 ); CRect rcRight( rc ); int nRight = rcExclude.right - rc.left; rcRight.OffsetRect( nRight, 0 ); bool bLeft = false; if ( ( rcLeft.left >= rcDesktop.top ) && ( rcRight.right <= rcDesktop.right ) ) { bLeft = ( nLeft < nRight ); } else if ( rcLeft.left >= rcDesktop.left ) { bLeft = true; } else if ( rcRight.right <= rcDesktop.right ) { bLeft = false; } else { ASSERT( false ); // this case is not supported yet } rc = bLeft ? rcLeft : rcRight; nFlags &= ~( TPM_HORPOSANIMATION | TPM_HORNEGANIMATION | TPM_VERPOSANIMATION | TPM_VERNEGANIMATION ); nFlags |= ( bLeft ? TPM_HORNEGANIMATION : TPM_HORPOSANIMATION ); } } Show( nFlags, rc ); }
// Updates the layout void CGeneralMsgBox::UpdateLayout() { // Caching the borders int cxLeft = FromDlgX(m_aMetrics[CX_LEFT_BORDER]); int cxRight = FromDlgX(m_aMetrics[CX_RIGHT_BORDER]); int cyTop = FromDlgY(m_aMetrics[CY_TOP_BORDER]); int cyBottom = FromDlgY(m_aMetrics[CY_BOTTOM_BORDER]); // Caching the space between buttons int cxBtnsSpace = FromDlgX(m_aMetrics[CX_BTNS_SPACE]); // The minimum dimensions of the client area // (starting with the message) CSize dimClient = m_dimMsg; int xMsg = 0; if (m_hIcon != NULL) { // Adding the icon xMsg = m_dimIcon.cx + FromDlgX(m_aMetrics[CX_ICON_MSG_SPACE]); dimClient.cx += xMsg; if (dimClient.cy < m_dimIcon.cy) dimClient.cy = m_dimIcon.cy; } xMsg += cxLeft; // Caching the minimum width needed for all buttons int cBtns = (int)m_aBtns.GetSize(); int cxBtns = (cBtns - 1) * FromDlgX(m_aMetrics[CX_BTNS_SPACE]) + cBtns * m_dimBtn.cx; if (dimClient.cx < cxBtns) dimClient.cx = cxBtns; dimClient.cx += cxLeft + cxRight; dimClient.cy += cyTop + cyBottom + m_dimBtn.cy + FromDlgY(m_aMetrics[CY_BTNS_MSG_SPACE]); // Set client dimensions CRect rc(0, 0, dimClient.cx, dimClient.cy); CalcWindowRect(rc); MoveWindow(rc); CenterWindow(); // Icon layout if (m_hIcon != NULL) m_stIconCtrl.MoveWindow(cxLeft, cyTop, m_dimIcon.cx, m_dimIcon.cy); // Message layout m_dimMsg.cx += 2; xMsg = (xMsg + dimClient.cx - cxRight - m_dimMsg.cx) / 2; m_edCtrl.MoveWindow(xMsg, cyTop, m_dimMsg.cx, m_dimMsg.cy); // Buttons layout int x = (dimClient.cx - cxBtns) / 2; int y = dimClient.cy - cyBottom - m_dimBtn.cy; for (int i = 0; i < cBtns; ++i) { CWnd* pWndCtrl = GetDlgItem(m_aBtns[i].uiIDC); pWndCtrl->MoveWindow(x, y, m_dimBtn.cx, m_dimBtn.cy); x += m_dimBtn.cx + cxBtnsSpace; } }
void CButtonDialog::PositionControls() { CSize sizeBase = GetBaseUnits(); int nButtonHeight = (sizeBase.cy*14)/8; int nHeight = 0; int nSep,nLeftMargin,nRightMargin,nTopMargin,nBottomMargin; int nButtonAdj; int nWidth = 0; CRect rectText; // a) 5/8 screen Width // b) Caption // c) nLeftMargin ICON nSep TEXT nRightMargin // d) nLeftMargin Button1 nSep Button2 ... nRightMargin // client width is max(b,d, min(c,a)) CSize sizeIcon(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)); nSep = sizeIcon.cx/2; nLeftMargin = nSep; nRightMargin = nSep; nTopMargin = nSep; nBottomMargin = nSep; CClientDC dc(this); CFont* pOldFont = dc.SelectObject(&m_font); nButtonAdj = dc.GetTextExtent(_T("XXX"),3).cx; // padding on buttons int nScreenWidth58 = dc.GetDeviceCaps(HORZRES)*5/8; int nCaptionWidth = dc.GetTextExtent(m_strCaption, m_strCaption. GetLength()).cx; CSize sizeText = dc.GetTextExtent(m_strText,m_strText.GetLength()); int nTextIconWidth = nLeftMargin+sizeIcon.cx+nSep+sizeText.cx+nRightMargin; int nButtons = (int)m_strArray.GetSize(); int nButtonsWidth = nLeftMargin+nRightMargin+(nButtons-1)*nSep; int i = 0; for (i=0;i<nButtons;i++) { nButtonsWidth += dc.GetTextExtent(m_strArray[i],m_strArray[i].GetLength()).cx+ nButtonAdj*2; } nWidth = min(nTextIconWidth,nScreenWidth58); nWidth = max(nWidth, nCaptionWidth); nWidth = max(nWidth, nButtonsWidth); m_staticIcon.SetWindowPos(NULL, nLeftMargin, nTopMargin, sizeIcon.cx, sizeIcon.cy, SWP_NOZORDER); if (sizeText.cx > nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep) { sizeText.cx = nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep; // int nTextWidth = nWidth-nLeftMargin-nRightMargin-sizeIcon.cx-nSep; // rectText.SetRect(0, 0, nTextWidth, 32767); rectText.SetRect(0, 0, sizeText.cx, 32767); /* Ask DrawText for the right cy */ sizeText.cy = dc.DrawText(m_strText, m_strText.GetLength(), &rectText, DT_CALCRECT | DT_WORDBREAK | DT_EXPANDTABS | DT_NOPREFIX); } m_staticText.SetWindowPos(NULL, nSep+sizeIcon.cx+nSep, nTopMargin, sizeText.cx, sizeText.cy, SWP_NOZORDER); sizeText.cy = max(sizeText.cy, sizeIcon.cy); // at least icon height nHeight = nTopMargin + sizeText.cy + nSep + nButtonHeight + nBottomMargin; CRect rect; rect.left = (nWidth - (nButtonsWidth - nLeftMargin - nRightMargin))/2; rect.top = nTopMargin + sizeText.cy + nSep; rect.bottom = rect.top + nButtonHeight; for (i=0;i<m_strArray.GetSize();i++) { rect.right = rect.left + dc.GetTextExtent(m_strArray[i],m_strArray[i].GetLength()).cx + 2*nButtonAdj; m_pButtons[i].MoveWindow(&rect); rect.left = rect.right + nSep; } rect.SetRect(0,0,nWidth,nHeight); CalcWindowRect(&rect); SetWindowPos(NULL, (dc.GetDeviceCaps(HORZRES)-rect.Width())/2, (dc.GetDeviceCaps(VERTRES)-rect.Height())/2, rect.Width(), rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE); if(m_nCancel == -1) // no cancel button { // CMenu* pMenu = GetSystemMenu(FALSE); // if (pMenu != NULL) // pMenu->DeleteMenu(SC_CLOSE, MF_BYCOMMAND); } dc.SelectObject(pOldFont); }