From 81b604e1f05359573c7f351d514faf240d3281f9 Mon Sep 17 00:00:00 2001 From: irwir Date: Sat, 21 Sep 2019 20:42:39 +0300 Subject: [PATCH] Slightly rearranged and optimized parts of the library code. --- ResizableComboBox/Demo.sln | 4 +-- ResizableLib/ResizableComboLBox.cpp | 2 +- ResizableLib/ResizableDialog.cpp | 5 ++-- ResizableLib/ResizableLayout.cpp | 3 ++- ResizableLib/ResizableSheet.cpp | 33 ++++++++++------------- ResizableLib/ResizableSheetEx.cpp | 41 +++++++++++------------------ 6 files changed, 38 insertions(+), 50 deletions(-) diff --git a/ResizableComboBox/Demo.sln b/ResizableComboBox/Demo.sln index 9af42e2..fe3c23e 100644 --- a/ResizableComboBox/Demo.sln +++ b/ResizableComboBox/Demo.sln @@ -3,10 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResizableLib", "..\ResizableLib\ResizableLib.vcxproj", "{C176053F-C799-4BF4-ABFA-125A4192CEB9}" -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo.vcxproj", "{E90C0521-E036-49C5-BC3E-F27276C73726}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ResizableLib", "..\ResizableLib\ResizableLib.vcxproj", "{C176053F-C799-4BF4-ABFA-125A4192CEB9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug Static Unicode|x86 = Debug Static Unicode|x86 diff --git a/ResizableLib/ResizableComboLBox.cpp b/ResizableLib/ResizableComboLBox.cpp index b573856..423b959 100644 --- a/ResizableLib/ResizableComboLBox.cpp +++ b/ResizableLib/ResizableComboLBox.cpp @@ -321,7 +321,7 @@ void CResizableComboLBox::ApplyLimitsToPos(WINDOWPOS* lpwndpos) // back to window rect rect = CRect(0, 0, 1, sizeClient.cy); - DWORD dwStyle = GetStyle(); + const DWORD dwStyle = GetStyle(); ::AdjustWindowRectEx(&rect, dwStyle, FALSE, GetExStyle()); lpwndpos->cy = rect.Height(); if (dwStyle & WS_HSCROLL) diff --git a/ResizableLib/ResizableDialog.cpp b/ResizableLib/ResizableDialog.cpp index 1cdab58..909330f 100644 --- a/ResizableLib/ResizableDialog.cpp +++ b/ResizableLib/ResizableDialog.cpp @@ -82,14 +82,15 @@ BOOL CResizableDialog::OnNcCreate(LPCREATESTRUCT lpCreateStruct) if (!CreateSizeGrip(!bChild)) return FALSE; + // Moved from behind if (!bChild) because user could resize the dialog smaller as in resource defined and that causes some static text to be clipped or dissapear. + MakeResizable(lpCreateStruct); + if (!bChild) { // set the initial size as the min track size SetMinTrackSize(CSize(lpCreateStruct->cx, lpCreateStruct->cy)); } - MakeResizable(lpCreateStruct); - return TRUE; } diff --git a/ResizableLib/ResizableLayout.cpp b/ResizableLib/ResizableLayout.cpp index 8550201..f99f9f6 100644 --- a/ResizableLib/ResizableLayout.cpp +++ b/ResizableLib/ResizableLayout.cpp @@ -689,7 +689,8 @@ void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout, NeedsRefresh(layout, rectChild, rectNew) : layout.properties.bCachedNeedsRefresh; // set flags - if (lpFlags) { + if (lpFlags) + { *lpFlags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION; if (bRefresh) *lpFlags |= SWP_NOCOPYBITS; diff --git a/ResizableLib/ResizableSheet.cpp b/ResizableLib/ResizableSheet.cpp index 9b2454e..91b6099 100644 --- a/ResizableLib/ResizableSheet.cpp +++ b/ResizableLib/ResizableSheet.cpp @@ -334,9 +334,6 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild, if (!GetAnchorMargins(pTab->m_hWnd, sizeChild, rectMargins)) return FALSE; - // get margin caused by tabcontrol - CRect rectTabMargins(0,0,0,0); - // get tab position after resizing and calc page rect CRect rectPage, rectSheet; GetTotalClientRect(&rectSheet); @@ -345,7 +342,7 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild, return FALSE; // no page yet // temporarily resize the tab control to calc page size - CRect rectSave; + CRect rectSave, rectTabMargins; pTab->GetWindowRect(rectSave); ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rectSave, 2); pTab->SetRedraw(FALSE); @@ -355,9 +352,9 @@ BOOL CResizableSheet::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild, pTab->SetRedraw(TRUE); // add non-client size - ::AdjustWindowRectEx(&rectTabMargins, GetStyle(), !(GetStyle() & WS_CHILD) && + const DWORD dwStyle = GetStyle(); + ::AdjustWindowRectEx(&rectTabMargins, dwStyle, !(dwStyle & WS_CHILD) && ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); - // compute extra size sizeExtra = rectMargins.TopLeft() + rectMargins.BottomRight() + rectTabMargins.Size(); @@ -371,22 +368,20 @@ void CResizableSheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) if (!GetTabControl()) return; - const int nCount = GetPageCount(); - for (int idx = 0; idx < nCount; ++idx) + int idx = GetPageCount(); + if (IsWizard()) // wizard mode { - if (IsWizard()) // wizard mode - { - // use pre-calculated margins - CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR)); - // add non-client size - ::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) && - ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); + CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR)); + const DWORD dwStyle = GetStyle(); + ::AdjustWindowRectEx(&rectExtra, dwStyle, !(dwStyle & WS_CHILD) && + ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); + while (--idx >= 0) ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size()); - } - else // tab mode - { + } + else // tab mode + { + while (--idx >= 0) ChainMinMaxInfoCB(lpMMI, *GetPage(idx)); - } } } diff --git a/ResizableLib/ResizableSheetEx.cpp b/ResizableLib/ResizableSheetEx.cpp index 3ef866a..38636bb 100644 --- a/ResizableLib/ResizableSheetEx.cpp +++ b/ResizableLib/ResizableSheetEx.cpp @@ -480,9 +480,6 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild if (!GetAnchorMargins(pTab->m_hWnd, sizeChild, rectMargins)) return FALSE; - // get margin caused by tabcontrol - CRect rectTabMargins(0,0,0,0); - // get tab position after resizing and calc page rect CRect rectPage, rectSheet; GetTotalClientRect(&rectSheet); @@ -491,7 +488,7 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild return FALSE; // no page yet // temporarily resize the tab control to calc page size - CRect rectSave; + CRect rectSave, rectTabMargins; pTab->GetWindowRect(rectSave); ::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rectSave, 2); pTab->SetRedraw(FALSE); @@ -501,40 +498,36 @@ BOOL CResizableSheetEx::CalcSizeExtra(HWND /*hWndChild*/, const CSize& sizeChild pTab->SetRedraw(TRUE); // add non-client size - ::AdjustWindowRectEx(&rectTabMargins, GetStyle(), !(GetStyle() & WS_CHILD) && + const DWORD dwStyle = GetStyle(); + ::AdjustWindowRectEx(&rectTabMargins, dwStyle, !(dwStyle & WS_CHILD) && ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); - // compute extra size sizeExtra = rectMargins.TopLeft() + rectMargins.BottomRight() + rectTabMargins.Size(); return TRUE; } -void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) +void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { MinMaxInfo(lpMMI); if (!GetTabControl()) return; - const int nCount = GetPageCount(); - for (int idx = 0; idx < nCount; ++idx) + int idx = GetPageCount(); + if (!IsWizard() && !IsWizard97()) // tab mode { - if (IsWizard()) // wizard mode - { - // use pre-calculated margins - CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR)); - // add non-client size - ::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) && - ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); - ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size()); - } - else if (IsWizard97()) // wizard 97 + while (--idx >= 0) + ChainMinMaxInfoCB(lpMMI, *GetPage(idx)); + } + else // wizard mode + { + while (--idx >= 0) { // use pre-calculated margins CRect rectExtra(-CPoint(m_sizePageTL), -CPoint(m_sizePageBR)); - if (!(GetPage(idx)->m_psp.dwFlags & PSP_HIDEHEADER)) + if (IsWizard97() && !(GetPage(idx)->m_psp.dwFlags & PSP_HIDEHEADER)) // wizard97 mode { // add header vertical offset CRect rectLine, rectSheet; @@ -543,15 +536,13 @@ void CResizableSheetEx::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) rectExtra.top = -rectLine.bottom; } + // add non-client size - ::AdjustWindowRectEx(&rectExtra, GetStyle(), !(GetStyle() & WS_CHILD) && + const DWORD dwStyle = GetStyle(); + ::AdjustWindowRectEx(&rectExtra, dwStyle, !(dwStyle & WS_CHILD) && ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle()); ChainMinMaxInfo(lpMMI, *GetPage(idx), rectExtra.Size()); } - else // tab mode - { - ChainMinMaxInfoCB(lpMMI, *GetPage(idx)); - } } }