Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.36 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "MyPropertySheet.h"
  3.  
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CMyPropertySheet
  6.  
  7. IMPLEMENT_DYNAMIC(CMyPropertySheet, CMFCPropertySheet)
  8.  
  9. CMyPropertySheet::CMyPropertySheet()
  10.     : m_sizePrev(0, 0)
  11.     , m_bInitialized(FALSE)
  12. {
  13. }
  14.  
  15. CMyPropertySheet::~CMyPropertySheet()
  16. {
  17. }
  18.  
  19. BEGIN_MESSAGE_MAP(CMyPropertySheet, CMFCPropertySheet)
  20.     ON_WM_SIZE()
  21. END_MESSAGE_MAP()
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CMyPropertySheet message handlers
  25.  
  26. BOOL CMyPropertySheet::OnInitDialog()
  27. {
  28.     BOOL bResult = CMFCPropertySheet::OnInitDialog();
  29.  
  30.     CRect rectClient;
  31.     GetClientRect(rectClient);
  32.  
  33.     m_sizePrev = rectClient.Size();
  34.     m_bInitialized = TRUE;
  35.  
  36.     return bResult;
  37. }
  38.  
  39. BOOL CMyPropertySheet::PreCreateWindow(CREATESTRUCT& cs)
  40. {
  41.     cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
  42.  
  43.     return CMFCPropertySheet::PreCreateWindow(cs);
  44. }
  45.  
  46. void CMyPropertySheet::OnSize(UINT nType, int cx, int cy)
  47. {
  48.     CMFCPropertySheet::OnSize(nType, cx, cy);
  49.  
  50.     AdjustControlsLayout();
  51. }
  52.  
  53. void CMyPropertySheet::AdjustControlsLayout()
  54. {
  55.     if (!m_bInitialized)
  56.     {
  57.         return;
  58.     }
  59.  
  60.     CWnd* pParentWnd = GetParent();
  61.     if (pParentWnd != NULL && !pParentWnd->IsWindowVisible())
  62.     {
  63.         return;
  64.     }
  65.  
  66.     ReposButtons(TRUE);
  67.  
  68.     CRect rectClient;
  69.     GetClientRect(rectClient);
  70.  
  71.     CSize sizeNew = rectClient.Size();
  72.  
  73.     const int dx = sizeNew.cx - m_sizePrev.cx;
  74.     const int dy = sizeNew.cy - m_sizePrev.cy;
  75.  
  76.     CWnd* pWndNavigator = NULL;
  77.  
  78.     if (m_wndOutlookBar.GetSafeHwnd() != NULL)
  79.     {
  80.         pWndNavigator = &m_wndOutlookBar;
  81.     }
  82.     else if (m_wndTree.GetSafeHwnd() != NULL)
  83.     {
  84.         pWndNavigator = &m_wndTree;
  85.     }
  86.     else if (m_wndList.GetSafeHwnd() != NULL)
  87.     {
  88.         pWndNavigator = &m_wndList;
  89.     }
  90.  
  91.     if (pWndNavigator->GetSafeHwnd() != NULL && dy != 0)
  92.     {
  93.         CRect rectNavigator;
  94.         pWndNavigator->GetWindowRect(rectNavigator);
  95.  
  96.         pWndNavigator->SetWindowPos(NULL, -1, -1,
  97.             rectNavigator.Width(),
  98.             rectNavigator.Height() + dy,
  99.             SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  100.     }
  101.  
  102.     CWnd* pWndTab = GetTabControl();
  103.  
  104.     if (m_wndTab.GetSafeHwnd() != NULL && m_wndTab.IsWindowVisible())
  105.     {
  106.         pWndTab = &m_wndTab;
  107.     }
  108.  
  109.     LockWindowUpdate();
  110.  
  111.     CPropertyPage* pPage = GetActivePage();
  112.  
  113.     if (pPage != NULL)
  114.     {
  115.         SetActivePage(pPage);
  116.     }
  117.  
  118.     if (pWndTab->GetSafeHwnd() != NULL)
  119.     {
  120.         ASSERT_VALID(pWndTab);
  121.  
  122.         CRect rectTab;
  123.         pWndTab->GetWindowRect(rectTab);
  124.  
  125.         pWndTab->SetWindowPos(NULL, -1, -1,
  126.             rectTab.Width() + dx,
  127.             rectTab.Height() + dy,
  128.             SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
  129.  
  130.         if (pPage->GetSafeHwnd() != NULL && m_wndTab.GetSafeHwnd() != NULL)
  131.         {
  132.             ((CMFCTabCtrl&)m_wndTab).SetActiveTab(GetPageIndex(pPage));
  133.         }
  134.     }
  135.  
  136.     UnlockWindowUpdate();
  137.  
  138.     m_sizePrev = sizeNew;
  139. }
  140.  
  141. int CMyPropertySheet::ReposButtons(BOOL bRedraw)
  142. {
  143.     const BOOL bIsRTL = (GetExStyle() & WS_EX_LAYOUTRTL);
  144.     const int nHorzMargin = 5;
  145.     const int nVertMargin = 5;
  146.  
  147.     int nButtonsHeight = 0;
  148.  
  149.     CRect rectClient;
  150.     GetClientRect(rectClient);
  151.  
  152.     int ids[] = { IDOK, ID_WIZBACK, ID_WIZNEXT, ID_WIZFINISH, IDCANCEL, ID_APPLY_NOW, IDHELP };
  153.  
  154.     int nTotalButtonsWidth = 0;
  155.  
  156.     for (int iStep = 0; iStep < (bIsRTL ? 1 : 2); iStep++)
  157.     {
  158.         for (int i = 0; i < sizeof(ids) / sizeof(ids[0]); i++)
  159.         {
  160.             CWnd* pButton = GetDlgItem(ids[i]);
  161.  
  162.             if (pButton != NULL && pButton->IsWindowVisible())
  163.             {
  164.                 if (ids[i] == IDHELP && (m_psh.dwFlags & PSH_HASHELP) == 0)
  165.                 {
  166.                     continue;
  167.                 }
  168.  
  169.                 if (ids[i] == ID_APPLY_NOW && (m_psh.dwFlags & PSH_NOAPPLYNOW))
  170.                 {
  171.                     continue;
  172.                 }
  173.  
  174.                 CRect rectButton;
  175.                 pButton->GetWindowRect(rectButton);
  176.                 ScreenToClient(rectButton);
  177.  
  178.                 if (iStep == 0)
  179.                 {
  180.                     // Align buttons at the bottom
  181.                     pButton->SetWindowPos(&wndTop, rectButton.left,
  182.                         rectClient.bottom - rectButton.Height() - nVertMargin,
  183.                         -1, -1, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  184.  
  185.                     nTotalButtonsWidth = rectButton.right;
  186.  
  187.                     nButtonsHeight = max(nButtonsHeight, rectButton.Height());
  188.                 }
  189.                 else
  190.                 {
  191.                     // Right align the buttons
  192.                     pButton->SetWindowPos(&wndTop,
  193.                         rectButton.left + rectClient.right - nTotalButtonsWidth - nHorzMargin,
  194.                         rectButton.top,
  195.                         -1, -1, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER);
  196.                 }
  197.  
  198.                 if (bRedraw)
  199.                 {
  200.                     pButton->RedrawWindow();
  201.                 }
  202.             }
  203.         }
  204.     }
  205.  
  206.     return nButtonsHeight;
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement