void CComPropertySheet::OnActivated(CPropertyPage* pPage) { if(!pPage) return; CRect bounds(30000,30000,-30000,-30000); CRect wr, cr; GetWindowRect(wr); GetClientRect(cr); CSize ws = wr.Size(), cs = cr.Size(); CRect twr, tcr; CTabCtrl* pTC = (CTabCtrl*)GetDlgItem(AFX_IDC_TAB_CONTROL); pTC->GetWindowRect(twr); pTC->GetClientRect(tcr); CSize tws = twr.Size(), tcs = tcr.Size(); if(CWnd* pChild = pPage->GetWindow(GW_CHILD)) { pChild->ModifyStyle(WS_CAPTION|WS_THICKFRAME, 0); pChild->ModifyStyleEx(WS_EX_DLGMODALFRAME, WS_EX_CONTROLPARENT); for(CWnd* pGrandChild = pChild->GetWindow(GW_CHILD); pGrandChild; pGrandChild = pGrandChild->GetNextWindow()) { if(!(pGrandChild->GetStyle()&WS_VISIBLE)) continue; CRect r; pGrandChild->GetWindowRect(&r); pChild->ScreenToClient(r); bounds |= r; } } bounds |= CRect(0,0,0,0); bounds.SetRect(0, 0, bounds.right + max(bounds.left, 4), bounds.bottom + max(bounds.top, 4)); CRect r = CRect(CPoint(0,0), bounds.Size()); pTC->AdjustRect(TRUE, r); r.SetRect(twr.TopLeft(), twr.TopLeft() + r.Size()); ScreenToClient(r); pTC->MoveWindow(r); pTC->ModifyStyle(TCS_MULTILINE, TCS_SINGLELINE); CSize diff = r.Size() - tws; if(!bounds.IsRectEmpty()) { if(CWnd* pChild = pPage->GetWindow(GW_CHILD)) pChild->MoveWindow(bounds); CRect r = twr; pTC->AdjustRect(FALSE, r); ScreenToClient(r); pPage->MoveWindow(CRect(r.TopLeft(), bounds.Size())); } int _afxPropSheetButtons[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP }; for(int i = 0; i < countof(_afxPropSheetButtons); i++) { if(CWnd* pWnd = GetDlgItem(_afxPropSheetButtons[i])) { pWnd->GetWindowRect(r); ScreenToClient(r); pWnd->MoveWindow(CRect(r.TopLeft() + diff, r.Size())); } } MoveWindow(CRect(wr.TopLeft(), ws + diff)); Invalidate(); }
//**************************************************************************************** BOOL CBCGPropertySheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); BOOL bReposButtons = FALSE; const int nVertMargin = 5; const int nHorzMargin = 5; CWnd* pWndNavigator = InitNavigationControl (); CRect rectClient; GetClientRect (rectClient); if (m_wndTab.GetSafeHwnd () != NULL) { CTabCtrl* pTab = GetTabControl (); ASSERT_VALID (pTab); CRect rectTab; pTab->GetWindowRect (rectTab); ScreenToClient (rectTab); rectTab.InflateRect (2, 0); if (pTab->GetItemCount () > 0) { CRect rectTabsNew; m_wndTab.GetTabsRect (rectTabsNew); CRect rectTabsOld; pTab->GetItemRect (0, rectTabsOld); const int nOldHeight = rectTabsOld.Height (); const int nNewHeight = rectTabsNew.Height (); if (nNewHeight > nOldHeight) { rectClient.bottom += nNewHeight - nOldHeight + nVertMargin; rectTab.bottom += nNewHeight - nOldHeight; SetWindowPos (NULL, -1, -1, rectClient.Width (), rectClient.Height (), SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } } m_wndTab.MoveWindow (rectTab); pTab->ModifyStyle (WS_TABSTOP, 0); pTab->ShowWindow (SW_HIDE); if (pTab->GetItemCount () > 0) { m_wndTab.SetActiveTab (0); } bReposButtons = TRUE; } else if (pWndNavigator != NULL) { CTabCtrl* pTab = GetTabControl (); ASSERT_VALID (pTab); pTab->ModifyStyle (WS_TABSTOP, 0); CRect rectTabItem; pTab->GetItemRect (0, rectTabItem); pTab->MapWindowPoints (this, &rectTabItem); const int nTabsHeight = rectTabItem.Height () + nVertMargin; SetWindowPos (NULL, -1, -1, rectClient.Width () + m_nBarWidth, rectClient.Height () - nTabsHeight + 4 * nVertMargin, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); GetClientRect (rectClient); pTab->MoveWindow (m_nBarWidth, -nTabsHeight, rectClient.right, rectClient.bottom - 2 * nVertMargin); CRect rectTab; pTab->GetWindowRect (rectTab); ScreenToClient (rectTab); CRect rectNavigator = rectClient; rectNavigator.right = rectNavigator.left + m_nBarWidth; rectNavigator.bottom = rectTab.bottom; rectNavigator.DeflateRect (1, 1); pWndNavigator->SetWindowPos (&wndTop, rectNavigator.left, rectNavigator.top, rectNavigator.Width (), rectNavigator.Height (), SWP_NOACTIVATE); SetActivePage (GetActivePage ()); bReposButtons = TRUE; } if (bReposButtons) { int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP }; int nTotalButtonsWidth = 0; for (int iStep = 0; iStep < 2; iStep++) { for (int i = 0; i < sizeof (ids) / sizeof (ids [0]); i++) { CWnd* pButton = GetDlgItem (ids[i]); if (pButton != NULL) { if (ids [i] == IDHELP && (m_psh.dwFlags & PSH_HASHELP) == 0) { continue; } if (ids [i] == ID_APPLY_NOW && (m_psh.dwFlags & PSH_NOAPPLYNOW)) { continue; } CRect rectButton; pButton->GetWindowRect (rectButton); ScreenToClient (rectButton); if (iStep == 0) { // Align buttons at the bottom pButton->SetWindowPos (&wndTop, rectButton.left, rectClient.bottom - rectButton.Height () - nVertMargin, -1, -1, SWP_NOSIZE | SWP_NOACTIVATE); nTotalButtonsWidth = rectButton.right; } else { // Right align the buttons pButton->SetWindowPos (&wndTop, rectButton.left + rectClient.right - nTotalButtonsWidth - nHorzMargin, rectButton.top, -1, -1, SWP_NOSIZE | SWP_NOACTIVATE); } } } } } return bResult; }
void CExtChildResizablePropertySheet::_TrickSyncActviveChild() { CPropertyPage * pWnd = CPropertySheet::GetActivePage(); CTabCtrl * pTabCtrl = CPropertySheet::GetTabControl(); if( pWnd != NULL && pWnd->GetSafeHwnd() != NULL && ::IsWindow( pWnd->GetSafeHwnd() ) && pTabCtrl != NULL && pTabCtrl->GetSafeHwnd() != NULL && ::IsWindow( pTabCtrl->GetSafeHwnd() ) ) { if( !m_bTabStylesInitialized ) { m_bTabStylesInitialized = true; DWORD dwStylesRemove = 0L; DWORD dwStylesAdd = 0L; if( m_bInitTabSingleLine ) { dwStylesRemove |= TCS_MULTILINE; dwStylesAdd |= TCS_SINGLELINE; } if( m_bInitTabButtons ) { dwStylesAdd |= TCS_BUTTONS; if( m_bInitTabButtonsFlat ) dwStylesAdd |= TCS_FLATBUTTONS; } if( dwStylesRemove != 0 || dwStylesAdd != 0 ) pTabCtrl->ModifyStyle( dwStylesRemove, dwStylesAdd, SWP_FRAMECHANGED ); if( m_bInitTabButtons && m_bInitTabButtonsFlat && m_bInitTabSeparatorsFlat ) pTabCtrl->SetExtendedStyle( TCS_EX_FLATSEPARATORS, TCS_EX_FLATSEPARATORS ); } RECT lpRect; GetClientRect(&lpRect); // dirty fix of the access vialation bug of // the tab control with single item when item's // width/height is same as tab control width/height __try { pTabCtrl->AdjustRect(FALSE, &lpRect); } __except( EXCEPTION_EXECUTE_HANDLER ) { lpRect.right ++; lpRect.bottom ++; __try { pTabCtrl->AdjustRect(FALSE, &lpRect); } __except( EXCEPTION_EXECUTE_HANDLER ) { } } pWnd->MoveWindow(&lpRect, TRUE); } }