Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "MyPropertySheet.h"
- /////////////////////////////////////////////////////////////////////////////
- // CMyPropertySheet
- IMPLEMENT_DYNAMIC(CMyPropertySheet, CMFCPropertySheet)
- CMyPropertySheet::CMyPropertySheet()
- : m_sizePrev(0, 0)
- , m_bInitialized(FALSE)
- {
- }
- CMyPropertySheet::~CMyPropertySheet()
- {
- }
- BEGIN_MESSAGE_MAP(CMyPropertySheet, CMFCPropertySheet)
- ON_WM_SIZE()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyPropertySheet message handlers
- BOOL CMyPropertySheet::OnInitDialog()
- {
- BOOL bResult = CMFCPropertySheet::OnInitDialog();
- CRect rectClient;
- GetClientRect(rectClient);
- m_sizePrev = rectClient.Size();
- m_bInitialized = TRUE;
- return bResult;
- }
- BOOL CMyPropertySheet::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
- return CMFCPropertySheet::PreCreateWindow(cs);
- }
- void CMyPropertySheet::OnSize(UINT nType, int cx, int cy)
- {
- CMFCPropertySheet::OnSize(nType, cx, cy);
- AdjustControlsLayout();
- }
- void CMyPropertySheet::AdjustControlsLayout()
- {
- if (!m_bInitialized)
- {
- return;
- }
- CWnd* pParentWnd = GetParent();
- if (pParentWnd != NULL && !pParentWnd->IsWindowVisible())
- {
- return;
- }
- ReposButtons(TRUE);
- CRect rectClient;
- GetClientRect(rectClient);
- CSize sizeNew = rectClient.Size();
- const int dx = sizeNew.cx - m_sizePrev.cx;
- const int dy = sizeNew.cy - m_sizePrev.cy;
- CWnd* pWndNavigator = NULL;
- if (m_wndOutlookBar.GetSafeHwnd() != NULL)
- {
- pWndNavigator = &m_wndOutlookBar;
- }
- else if (m_wndTree.GetSafeHwnd() != NULL)
- {
- pWndNavigator = &m_wndTree;
- }
- else if (m_wndList.GetSafeHwnd() != NULL)
- {
- pWndNavigator = &m_wndList;
- }
- if (pWndNavigator->GetSafeHwnd() != NULL && dy != 0)
- {
- CRect rectNavigator;
- pWndNavigator->GetWindowRect(rectNavigator);
- pWndNavigator->SetWindowPos(NULL, -1, -1,
- rectNavigator.Width(),
- rectNavigator.Height() + dy,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- }
- CWnd* pWndTab = GetTabControl();
- if (m_wndTab.GetSafeHwnd() != NULL && m_wndTab.IsWindowVisible())
- {
- pWndTab = &m_wndTab;
- }
- LockWindowUpdate();
- CPropertyPage* pPage = GetActivePage();
- if (pPage != NULL)
- {
- SetActivePage(pPage);
- }
- if (pWndTab->GetSafeHwnd() != NULL)
- {
- ASSERT_VALID(pWndTab);
- CRect rectTab;
- pWndTab->GetWindowRect(rectTab);
- pWndTab->SetWindowPos(NULL, -1, -1,
- rectTab.Width() + dx,
- rectTab.Height() + dy,
- SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
- if (pPage->GetSafeHwnd() != NULL && m_wndTab.GetSafeHwnd() != NULL)
- {
- ((CMFCTabCtrl&)m_wndTab).SetActiveTab(GetPageIndex(pPage));
- }
- }
- UnlockWindowUpdate();
- m_sizePrev = sizeNew;
- }
- int CMyPropertySheet::ReposButtons(BOOL bRedraw)
- {
- const BOOL bIsRTL = (GetExStyle() & WS_EX_LAYOUTRTL);
- const int nHorzMargin = 5;
- const int nVertMargin = 5;
- int nButtonsHeight = 0;
- CRect rectClient;
- GetClientRect(rectClient);
- int ids[] = { IDOK, ID_WIZBACK, ID_WIZNEXT, ID_WIZFINISH, IDCANCEL, ID_APPLY_NOW, IDHELP };
- int nTotalButtonsWidth = 0;
- for (int iStep = 0; iStep < (bIsRTL ? 1 : 2); iStep++)
- {
- for (int i = 0; i < sizeof(ids) / sizeof(ids[0]); i++)
- {
- CWnd* pButton = GetDlgItem(ids[i]);
- if (pButton != NULL && pButton->IsWindowVisible())
- {
- 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 | SWP_NOZORDER);
- nTotalButtonsWidth = rectButton.right;
- nButtonsHeight = max(nButtonsHeight, rectButton.Height());
- }
- else
- {
- // Right align the buttons
- pButton->SetWindowPos(&wndTop,
- rectButton.left + rectClient.right - nTotalButtonsWidth - nHorzMargin,
- rectButton.top,
- -1, -1, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
- }
- if (bRedraw)
- {
- pButton->RedrawWindow();
- }
- }
- }
- }
- return nButtonsHeight;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement