diff --git a/ResizableLib/ResizableComboBox.cpp b/ResizableLib/ResizableComboBox.cpp index ee89832..7181b3a 100644 --- a/ResizableLib/ResizableComboBox.cpp +++ b/ResizableLib/ResizableComboBox.cpp @@ -28,6 +28,7 @@ static char THIS_FILE[] = __FILE__; // CResizableComboBox CResizableComboBox::CResizableComboBox() + : m_rectDropDown(), m_iExtent(0) { m_bClipMaxHeight = TRUE; m_bIntegralHeight = TRUE; @@ -49,10 +50,10 @@ END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CResizableComboBox message handlers -HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) +HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor); - + if (nCtlColor == CTLCOLOR_LISTBOX) { if (!(GetStyle() & CBS_SIMPLE) @@ -69,7 +70,7 @@ HBRUSH CResizableComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) return hbr; } -LRESULT CResizableComboBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CResizableComboBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { @@ -110,7 +111,7 @@ void CResizableComboBox::InitHorizontalExtent() CFont* pOldFont = dc.SelectObject(GetFont()); CString str; - + m_iExtent = 0; int n = GetCount(); for (int i=0; im_rectDropDown); diff --git a/ResizableLib/ResizableComboLBox.h b/ResizableLib/ResizableComboLBox.h index 86fca95..9f42f16 100644 --- a/ResizableLib/ResizableComboLBox.h +++ b/ResizableLib/ResizableComboLBox.h @@ -77,7 +77,7 @@ class CResizableComboLBox : public CWnd, public CResizableGrip virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizableDialog.h b/ResizableLib/ResizableDialog.h index 46d9026..7814b60 100644 --- a/ResizableLib/ResizableDialog.h +++ b/ResizableLib/ResizableDialog.h @@ -38,8 +38,8 @@ class CResizableDialog : public CDialog, public CResizableLayout, // Construction public: CResizableDialog(); - CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL); - CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL); + explicit CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL); + explicit CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL); // Attributes private: @@ -79,7 +79,7 @@ class CResizableDialog : public CDialog, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizableFormView.h b/ResizableLib/ResizableFormView.h index c8e082d..e1ab558 100644 --- a/ResizableLib/ResizableFormView.h +++ b/ResizableLib/ResizableFormView.h @@ -38,13 +38,13 @@ class CResizableFormView : public CFormView, public CResizableLayout, // Construction protected: // must derive your own class - CResizableFormView(UINT nIDTemplate); - CResizableFormView(LPCTSTR lpszTemplateName); + explicit CResizableFormView(UINT nIDTemplate); + explicit CResizableFormView(LPCTSTR lpszTemplateName); virtual ~CResizableFormView(); private: void PrivateConstruct(); - + // support for temporarily hiding the grip DWORD m_dwGripTempState; enum GripHideReason // bitmask @@ -62,7 +62,7 @@ class CResizableFormView : public CFormView, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; diff --git a/ResizableLib/ResizableFrame.h b/ResizableLib/ResizableFrame.h index f29c950..12349c3 100644 --- a/ResizableLib/ResizableFrame.h +++ b/ResizableLib/ResizableFrame.h @@ -57,7 +57,7 @@ class CResizableFrame : public CFrameWnd, public CResizableMinMax, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; private: diff --git a/ResizableLib/ResizableGrip.cpp b/ResizableLib/ResizableGrip.cpp index 744a00b..44aa8ba 100644 --- a/ResizableLib/ResizableGrip.cpp +++ b/ResizableLib/ResizableGrip.cpp @@ -34,16 +34,18 @@ static char THIS_FILE[]=__FILE__; CResizableGrip::CResizableGrip() { m_nShowCount = 0; + m_wndGrip = new CSizeGrip(); } CResizableGrip::~CResizableGrip() { - + m_wndGrip->DestroyWindow(); + delete m_wndGrip; } void CResizableGrip::UpdateSizeGrip() { - if (!::IsWindow(m_wndGrip.m_hWnd)) + if (!::IsWindow(m_wndGrip->m_hWnd)) return; // size-grip goes bottom right in the client area @@ -52,11 +54,11 @@ void CResizableGrip::UpdateSizeGrip() RECT rect; GetResizableWnd()->GetClientRect(&rect); - rect.left = rect.right - m_wndGrip.m_size.cx; - rect.top = rect.bottom - m_wndGrip.m_size.cy; + rect.left = rect.right - m_wndGrip->m_size.cx; + rect.top = rect.bottom - m_wndGrip->m_size.cy; // must stay below other children - m_wndGrip.SetWindowPos(&CWnd::wndBottom, rect.left, rect.top, 0, 0, + m_wndGrip->SetWindowPos(&CWnd::wndBottom, rect.left, rect.top, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREPOSITION | (IsSizeGripVisible() ? SWP_SHOWWINDOW : SWP_HIDEWINDOW)); } @@ -106,12 +108,12 @@ void CResizableGrip::SetSizeGripVisibility(BOOL bVisible) BOOL CResizableGrip::SetSizeGripBkMode(int nBkMode) { - if (::IsWindow(m_wndGrip.m_hWnd)) + if (::IsWindow(m_wndGrip->m_hWnd)) { if (nBkMode == OPAQUE) - m_wndGrip.SetTransparency(FALSE); + m_wndGrip->SetTransparency(FALSE); else if (nBkMode == TRANSPARENT) - m_wndGrip.SetTransparency(TRUE); + m_wndGrip->SetTransparency(TRUE); else return FALSE; return TRUE; @@ -121,25 +123,25 @@ BOOL CResizableGrip::SetSizeGripBkMode(int nBkMode) void CResizableGrip::SetSizeGripShape(BOOL bTriangular) { - if (::IsWindow(m_wndGrip.m_hWnd)) - m_wndGrip.SetTriangularShape(bTriangular); + if (::IsWindow(m_wndGrip->m_hWnd)) + m_wndGrip->SetTriangularShape(bTriangular); } BOOL CResizableGrip::CreateSizeGrip(BOOL bVisible /*= TRUE*/, BOOL bTriangular /*= TRUE*/, BOOL bTransparent /*= FALSE*/) { // create grip - CRect rect(0 , 0, m_wndGrip.m_size.cx, m_wndGrip.m_size.cy); - BOOL bRet = m_wndGrip.Create(WS_CHILD | WS_CLIPSIBLINGS + CRect rect(0 , 0, m_wndGrip->m_size.cx, m_wndGrip->m_size.cy); + BOOL bRet = m_wndGrip->Create(WS_CHILD | WS_CLIPSIBLINGS | SBS_SIZEGRIP, rect, GetResizableWnd(), 0); if (bRet) { // set options - m_wndGrip.SetTriangularShape(bTriangular); - m_wndGrip.SetTransparency(bTransparent); + m_wndGrip->SetTriangularShape(bTriangular); + m_wndGrip->SetTransparency(bTransparent); SetSizeGripVisibility(bVisible); - + // update position UpdateSizeGrip(); } @@ -155,7 +157,7 @@ BOOL CResizableGrip::CSizeGrip::IsRTL() return GetExStyle() & WS_EX_LAYOUTRTL; } -BOOL CResizableGrip::CSizeGrip::PreCreateWindow(CREATESTRUCT& cs) +BOOL CResizableGrip::CSizeGrip::PreCreateWindow(CREATESTRUCT& cs) { // set window size m_size.cx = GetSystemMetrics(SM_CXVSCROLL); @@ -163,7 +165,7 @@ BOOL CResizableGrip::CSizeGrip::PreCreateWindow(CREATESTRUCT& cs) cs.cx = m_size.cx; cs.cy = m_size.cy; - + return CScrollBar::PreCreateWindow(cs); } @@ -188,7 +190,6 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message, return HTBOTTOMLEFT; else return HTBOTTOMRIGHT; - break; case WM_SETTINGCHANGE: { @@ -249,7 +250,7 @@ LRESULT CResizableGrip::CSizeGrip::WindowProc(UINT message, m_dcGrip.SetBkColor(m_dcGrip.GetPixel(0, 0)); m_dcMask.BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcGrip, 0, 0, SRCCOPY); m_dcGrip.BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcMask, 0, 0, 0x00220326); - + // draw transparently pDC->BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcMask, 0, 0, SRCAND); pDC->BitBlt(0, 0, m_size.cx, m_size.cy, &m_dcGrip, 0, 0, SRCPAINT); diff --git a/ResizableLib/ResizableGrip.h b/ResizableLib/ResizableGrip.h index 1a1181e..97603c8 100644 --- a/ResizableLib/ResizableGrip.h +++ b/ResizableLib/ResizableGrip.h @@ -33,13 +33,14 @@ /*! * long_description */ -class CResizableGrip +class CResizableGrip { private: class CSizeGrip : public CScrollBar { public: CSizeGrip() + : m_size() { m_bTransparent = FALSE; m_bTriangular = FALSE; @@ -65,7 +66,7 @@ class CResizableGrip CBitmap m_bmGrip, m_bmMask; }; - CSizeGrip m_wndGrip; // grip control + CSizeGrip *m_wndGrip; // grip control int m_nShowCount; // support for hiding the grip protected: diff --git a/ResizableLib/ResizableLayout.cpp b/ResizableLib/ResizableLayout.cpp index 8618449..61234a2 100644 --- a/ResizableLib/ResizableLayout.cpp +++ b/ResizableLib/ResizableLayout.cpp @@ -44,7 +44,7 @@ static char THIS_FILE[]=__FILE__; /*! * This function adds a new control to the layout manager and sets anchor * points for its top-left and bottom-right corners. - * + * * @param hWnd Window handle to the control to be added * @param anchorTopLeft Anchor point for the top-left corner * @param anchorBottomRight Anchor point for the bottom-right corner @@ -82,7 +82,7 @@ void CResizableLayout::AddAnchor(HWND hWnd, ANCHOR anchorTopLeft, ANCHOR anchorB marginTopLeft.cx = rectChild.left - rectParent.Width() * anchorTopLeft.cx / 100; marginTopLeft.cy = rectChild.top - rectParent.Height() * anchorTopLeft.cy / 100; - + // calculate margin for the bottom-right corner marginBottomRight.cx = rectChild.right - rectParent.Width() * anchorBottomRight.cx / 100; @@ -111,7 +111,7 @@ void CResizableLayout::AddAnchor(HWND hWnd, ANCHOR anchorTopLeft, ANCHOR anchorB /*! * This function adds all the controls not yet added to the layout manager * and sets anchor points for its top-left and bottom-right corners. - * + * * @param anchor Anchor point for the top-left and bottom-right corner * * @remarks Overlapping controls, like group boxes and the controls inside, @@ -126,7 +126,7 @@ void CResizableLayout::AddAllOtherAnchors(ANCHOR anchor) ASSERT(::IsWindow(hParent)); HWND hWnd = ::GetWindow(hParent, GW_CHILD); - while (hWnd != NULL) + while (hWnd != NULL) { POSITION pos; if (!m_mapLayout.Lookup(hWnd, pos)) @@ -164,13 +164,13 @@ UINT CResizableLayout::AddAnchorCallback() /*! * This function is called for each placeholder added to the layout manager * and must be overridden to provide the necessary layout information. - * + * * @param layout Reference to a LAYOUTINFO structure to be filled with * layout information for the specified placeholder. * On input, nCallbackID is the identification number * returned by AddAnchorCallback. On output, anchor points and * the window handle must be set and valid. - * + * * @return The return value is @c TRUE if the layout information has been * provided successfully, @c FALSE to skip this placeholder. * @@ -183,9 +183,9 @@ UINT CResizableLayout::AddAnchorCallback() BOOL CResizableLayout::ArrangeLayoutCallback(LAYOUTINFO& layout) const { UNREFERENCED_PARAMETER(layout); - + ASSERT(FALSE); // must be overridden, if callback is used - + return FALSE; // no useful output data } @@ -197,7 +197,7 @@ BOOL CResizableLayout::ArrangeLayoutCallback(LAYOUTINFO& layout) const * once for performace reasons, so all the controls are in their * old position when AddAnchorCallback is called. * To know where a control will be placed use GetAnchorPosition. - * + * * @sa AddAnchor AddAnchorCallback ArrangeLayoutCallback GetAnchorPosition */ void CResizableLayout::ArrangeLayout() const @@ -217,15 +217,15 @@ void CResizableLayout::ArrangeLayout() const // reposition child windows HDWP hdwp = ::BeginDeferWindowPos(count + countCB); - + POSITION pos = m_listLayout.GetHeadPosition(); while (pos != NULL) { // get layout info layout = m_listLayout.GetNext(pos); - + // calculate new child's position, size and flags for SetWindowPos - CalcNewChildPosition(layout, rectParent, rectChild, uFlags); + CalcNewChildPosition(layout, rectParent, rectChild, &uFlags); // only if size or position changed if ((uFlags & (SWP_NOMOVE|SWP_NOSIZE)) != (SWP_NOMOVE|SWP_NOSIZE)) @@ -248,7 +248,7 @@ void CResizableLayout::ArrangeLayout() const continue; // calculate new child's position, size and flags for SetWindowPos - CalcNewChildPosition(layout, rectParent, rectChild, uFlags); + CalcNewChildPosition(layout, rectParent, rectChild, &uFlags); // only if size or position changed if ((uFlags & (SWP_NOMOVE|SWP_NOSIZE)) != (SWP_NOMOVE|SWP_NOSIZE)) @@ -311,7 +311,7 @@ void CResizableLayout::ClipChildWindow(const LAYOUTINFO& layout, * This function retrieves the clipping region for the current layout. * It can be used to draw directly inside the region, without applying * clipping as the ClipChildren function does. - * + * * @param pRegion Pointer to a CRegion object that holds the * calculated clipping region upon return * @@ -344,7 +344,7 @@ void CResizableLayout::GetClippingRegion(CRgn* pRegion) const { // get layout info layout = m_listLayout.GetNext(pos); - + if (::IsWindowVisible(layout.hWnd)) ClipChildWindow(layout, pRegion); } @@ -383,10 +383,10 @@ inline CWnd* GetRootParentWnd(CWnd* pWnd) * This function enables or restores clipping on the specified DC when * appropriate. It should be called whenever drawing on the window client * area to avoid flickering. - * - * @param pDC Pointer to the target device context + * + * @param pDC Pointer to the target device context * @param bUndo Flag that specifies wether to restore the clipping region - * + * * @return The return value is @c TRUE if the clipping region has been * modified, @c FALSE if clipping was not necessary. * @@ -441,7 +441,7 @@ BOOL CResizableLayout::ClipChildren(CDC* pDC, BOOL bUndo) ::SelectClipRgn(hDC, m_hOldClipRgn); else ::SelectClipRgn(hDC, NULL); - + return TRUE; } @@ -453,7 +453,7 @@ BOOL CResizableLayout::ClipChildren(CDC* pDC, BOOL bUndo) * classes too, in place of the standard GetClientRect. It can be useful * for windows with scrollbars or expanding windows, to provide the true * client area, including even those parts which are not visible. - * + * * @param lpRect Pointer to the RECT structure that holds the result * * @remarks Override this function to provide the client area the class uses @@ -469,13 +469,13 @@ void CResizableLayout::GetTotalClientRect(LPRECT lpRect) const /*! * This function is used to determine if a control needs to be painted when * it is moved or resized by the layout manager. - * + * * @param layout Reference to a @c LAYOUTINFO structure for the control * @param rectOld Reference to a @c RECT structure that holds the control * position and size before the layout update * @param rectNew Reference to a @c RECT structure that holds the control * position and size after the layout update - * + * * @return The return value is @c TRUE if the control should be freshly * painted after a layout update, @c FALSE if not necessary. * @@ -562,10 +562,10 @@ BOOL CResizableLayout::NeedsRefresh(const LAYOUTINFO& layout, SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO); info.fMask = SIF_PAGE | SIF_POS | SIF_RANGE; - if (::GetScrollInfo(layout.hWnd, SB_HORZ, &info)) + if (::GetScrollInfo(layout.hWnd, SB_HORZ, &info) && info.nPage > 1) //fix for unsigned subtraction { // subtract the page size - info.nMax -= __max(info.nPage - 1, 0); + info.nMax -= info.nPage-1; //should not use __max() macro } // resizing will cause the text to scroll on the right @@ -584,9 +584,9 @@ BOOL CResizableLayout::NeedsRefresh(const LAYOUTINFO& layout, * This function is used to determine if a control can be safely clipped * out of the parent window client area when it is repainted, usually * after a resize operation. - * + * * @param layout Reference to a @c LAYOUTINFO structure for the control - * + * * @return The return value is @c TRUE if clipping is supported by the * control, @c FALSE otherwise. * @@ -649,14 +649,12 @@ BOOL CResizableLayout::LikesClipping(const LAYOUTINFO& layout) const case SS_BITMAP: // bitmaps return TRUE; - break; case SS_ICON: case SS_ENHMETAFILE: if (style & SS_CENTERIMAGE) return FALSE; return TRUE; - break; default: return FALSE; @@ -673,19 +671,19 @@ BOOL CResizableLayout::LikesClipping(const LAYOUTINFO& layout) const * control in the layout and flags for @c SetWindowPos */ void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout, - const CRect &rectParent, CRect &rectChild, UINT& uFlags) const + const CRect &rectParent, CRect &rectChild, UINT *lpFlags) const { CWnd* pParent = GetResizableWnd(); ::GetWindowRect(layout.hWnd, &rectChild); ::MapWindowPoints(NULL, pParent->m_hWnd, (LPPOINT)&rectChild, 2); - + CRect rectNew; // calculate new top-left corner rectNew.left = layout.marginTopLeft.cx + rectParent.Width() * layout.anchorTopLeft.cx / 100; rectNew.top = layout.marginTopLeft.cy + rectParent.Height() * layout.anchorTopLeft.cy / 100; - + // calculate new bottom-right corner rectNew.right = layout.marginBottomRight.cx + rectParent.Width() * layout.anchorBottomRight.cx / 100; rectNew.bottom = layout.marginBottomRight.cy + rectParent.Height() * layout.anchorBottomRight.cy / 100; @@ -697,14 +695,16 @@ void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout, BOOL bRefresh = layout.properties.bAskRefresh ? NeedsRefresh(layout, rectChild, rectNew) : layout.properties.bCachedNeedsRefresh; - // set flags - uFlags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION; - if (bRefresh) - uFlags |= SWP_NOCOPYBITS; - if (rectNew.TopLeft() == rectChild.TopLeft()) - uFlags |= SWP_NOMOVE; - if (rectNew.Size() == rectChild.Size()) - uFlags |= SWP_NOSIZE; + // set flags + if (lpFlags) { + *lpFlags = SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREPOSITION; + if (bRefresh) + *lpFlags |= SWP_NOCOPYBITS; + if (rectNew.TopLeft() == rectChild.TopLeft()) + *lpFlags |= SWP_NOMOVE; + if (rectNew.Size() == rectChild.Size()) + *lpFlags |= SWP_NOSIZE; + } // update rect rectChild = rectNew; @@ -713,11 +713,11 @@ void CResizableLayout::CalcNewChildPosition(const LAYOUTINFO& layout, /*! * This function calculates the top, left, bottom, right margins for a * given size of the specified control. - * + * * @param hWnd Window handle to a control in the layout * @param sizeChild Size of the control to use in calculations * @param rectMargins Holds the calculated margins - * + * * @return The return value is @c TRUE if successful, @c FALSE otherwise * * @remarks This function can be used to infer the parent window size @@ -752,7 +752,7 @@ BOOL CResizableLayout::GetAnchorMargins(HWND hWnd, const CSize &sizeChild, CRect * This function is used to set the initial resize properties of a control * in the layout, that are stored in the @c properties member of the * related @c LAYOUTINFO structure. - * + * * @param layout Reference to the @c LAYOUTINFO structure to be set * * @remarks The various flags are used to specify whether the resize @@ -760,7 +760,7 @@ BOOL CResizableLayout::GetAnchorMargins(HWND hWnd, const CSize &sizeChild, CRect * call to the property querying functions is needed at every * layout update, or they are static properties, and the cached * value is used whenever necessary. - * @n The default implementation sends a registered message to the + * @n The default implementation sends a registered message to the * control, giving it the opportunity to specify its resize * properties, which takes precedence if the message is supported. * It then sets the @a clipping property as static, calling @@ -794,15 +794,15 @@ void CResizableLayout::InitResizeProperties(LAYOUTINFO &layout) const /*! * This function modifies a window to enable resizing functionality. * This affects the window style, size, system menu and appearance. - * + * * @param lpCreateStruct Pointer to a @c CREATESTRUCT structure, usually * passed by the system to the window procedure in a @c WM_CREATE * or @c WM_NCCREATE - * + * * @remarks The function is intended to be called only inside a @c WM_CREATE * or @c WM_NCCREATE message handler. */ -void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct) +void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct) const { if (lpCreateStruct->style & WS_CHILD) return; @@ -838,7 +838,7 @@ void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct) /*! * This function should be called inside the parent window @c WM_NCCALCSIZE * message handler to help eliminate flickering. - * + * * @param bAfterDefault Flag that specifies wether the call is made before * or after the default handler * @param lpncsp Pointer to the @c NCCALCSIZE_PARAMS structure that is @@ -846,7 +846,7 @@ void CResizableLayout::MakeResizable(LPCREATESTRUCT lpCreateStruct) * @param lResult Reference to the result of the message handler. * It contains the default handler result on input and the value to * return from the window procedure on output. - * + * * @remarks This function fixes the annoying flickering effect that is * visible when resizing the top or left edges of the window * (at least on a "left to right" Windows localized version). diff --git a/ResizableLib/ResizableLayout.h b/ResizableLib/ResizableLayout.h index 589567c..cdc135a 100644 --- a/ResizableLib/ResizableLayout.h +++ b/ResizableLib/ResizableLayout.h @@ -21,7 +21,7 @@ #if !defined(AFX_RESIZABLELAYOUT_H__INCLUDED_) #define AFX_RESIZABLELAYOUT_H__INCLUDED_ -#include +//#include #include "ResizableMsgSupport.h" #if _MSC_VER > 1000 @@ -43,7 +43,7 @@ typedef struct tagANCHOR int cx; //!< horizontal component, in percent int cy; //!< vertical component, in percent - tagANCHOR() {} + tagANCHOR() : cx(0), cy(0) {} tagANCHOR(int x, int y) { @@ -97,7 +97,7 @@ typedef struct tagLAYOUTINFO ANCHOR anchorTopLeft; //! Fixed distance for the top-left corner SIZE marginTopLeft; - + //! Anchor point for the bottom-right corner ANCHOR anchorBottomRight; //! Fixed distance for the bottom-right corner @@ -109,11 +109,12 @@ typedef struct tagLAYOUTINFO RESIZEPROPERTIES properties; tagLAYOUTINFO() : hWnd(NULL), nCallbackID(0), bMsgSupport(FALSE) + , marginTopLeft(), marginBottomRight() { sWndClass[0] = 0; } - tagLAYOUTINFO(HWND hwnd, ANCHOR tl_type, SIZE tl_margin, + tagLAYOUTINFO(HWND hwnd, ANCHOR tl_type, SIZE tl_margin, ANCHOR br_type, SIZE br_margin) : hWnd(hwnd), nCallbackID(0), bMsgSupport(FALSE), @@ -159,7 +160,7 @@ class CResizableLayout //! @brief Helper function to calculate new layout void CalcNewChildPosition(const LAYOUTINFO &layout, - const CRect &rectParent, CRect &rectChild, UINT& uFlags) const; + const CRect &rectParent, CRect &rectChild, UINT *lpFlags) const; protected: //! @brief Override to initialize resize properties (clipping, refresh) @@ -177,7 +178,7 @@ class CResizableLayout //! @brief Get the layout clipping region void GetClippingRegion(CRgn* pRegion) const; - + //! @brief Override for scrollable or expanding parent windows virtual void GetTotalClientRect(LPRECT lpRect) const; @@ -225,9 +226,7 @@ class CResizableLayout if (!m_mapLayout.Lookup(hWnd, pos)) return FALSE; - UINT uTmpFlags; - CalcNewChildPosition(m_listLayout.GetAt(pos), rectParent, rectChild, - (lpFlags != NULL) ? (*lpFlags) : uTmpFlags); + CalcNewChildPosition(m_listLayout.GetAt(pos), rectParent, rectChild, lpFlags); return TRUE; } @@ -287,12 +286,13 @@ class CResizableLayout //! @brief Enhance anti-flickering void HandleNcCalcSize(BOOL bAfterDefault, LPNCCALCSIZE_PARAMS lpncsp, LRESULT& lResult); - + //! @brief Enable resizable style for top level parent windows - void MakeResizable(LPCREATESTRUCT lpCreateStruct); + void MakeResizable(LPCREATESTRUCT lpCreateStruct) const; public: CResizableLayout() + : m_rectClientBefore() { m_bNoRecursion = FALSE; m_hOldClipRgn = ::CreateRectRgn(0,0,0,0); diff --git a/ResizableLib/ResizableMDIChild.h b/ResizableLib/ResizableMDIChild.h index 79e30f2..a4ccd97 100644 --- a/ResizableLib/ResizableMDIChild.h +++ b/ResizableLib/ResizableMDIChild.h @@ -57,7 +57,7 @@ class CResizableMDIChild : public CMDIChildWnd, public CResizableMinMax, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; private: diff --git a/ResizableLib/ResizableMDIFrame.h b/ResizableLib/ResizableMDIFrame.h index 05e1a2c..fed3a5f 100644 --- a/ResizableLib/ResizableMDIFrame.h +++ b/ResizableLib/ResizableMDIFrame.h @@ -58,7 +58,7 @@ class CResizableMDIFrame : public CMDIFrameWnd, public CResizableMinMax, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; private: diff --git a/ResizableLib/ResizableMinMax.cpp b/ResizableLib/ResizableMinMax.cpp index 4072026..12ecfd5 100644 --- a/ResizableLib/ResizableMinMax.cpp +++ b/ResizableLib/ResizableMinMax.cpp @@ -32,6 +32,7 @@ static char THIS_FILE[]=__FILE__; ////////////////////////////////////////////////////////////////////// CResizableMinMax::CResizableMinMax() + : m_ptMinTrackSize(), m_ptMaxTrackSize(), m_ptMaxPos(), m_ptMaxSize() { m_bUseMinTrack = FALSE; m_bUseMaxTrack = FALSE; @@ -43,7 +44,7 @@ CResizableMinMax::~CResizableMinMax() } -void CResizableMinMax::MinMaxInfo(LPMINMAXINFO lpMMI) +void CResizableMinMax::MinMaxInfo(LPMINMAXINFO lpMMI) const { if (m_bUseMinTrack) lpMMI->ptMinTrackSize = m_ptMinTrackSize; diff --git a/ResizableLib/ResizableMinMax.h b/ResizableLib/ResizableMinMax.h index 1c64f9c..8f7fe4f 100644 --- a/ResizableLib/ResizableMinMax.h +++ b/ResizableLib/ResizableMinMax.h @@ -52,12 +52,12 @@ class CResizableMinMax virtual ~CResizableMinMax(); protected: - void MinMaxInfo(LPMINMAXINFO lpMMI); - void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, CWnd* pWnd); + void MinMaxInfo(LPMINMAXINFO lpMMI) const; + static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentFrame, CWnd* pWnd); - void ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, CSize sizeExtra); - - void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentWnd, UINT nID, CSize sizeExtra) + static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, HWND hWndChild, CSize sizeExtra); + + static void ChainMinMaxInfo(LPMINMAXINFO lpMMI, CWnd* pParentWnd, UINT nID, CSize sizeExtra) { ChainMinMaxInfo(lpMMI, ::GetDlgItem(pParentWnd->GetSafeHwnd(), nID), sizeExtra); diff --git a/ResizableLib/ResizableMsgSupport.h b/ResizableLib/ResizableMsgSupport.h index 06cbd31..b40c0da 100644 --- a/ResizableLib/ResizableMsgSupport.h +++ b/ResizableLib/ResizableMsgSupport.h @@ -54,7 +54,7 @@ typedef struct tagREFRESHPROPERTY RECT rcNew; // initialize with valid data - tagREFRESHPROPERTY() : bNeedsRefresh(TRUE) {} + tagREFRESHPROPERTY() : bNeedsRefresh(TRUE), rcOld(), rcNew() {} } REFRESHPROPERTY, *PREFRESHPROPERTY, *LPREFRESHPROPERTY; diff --git a/ResizableLib/ResizablePage.h b/ResizableLib/ResizablePage.h index 4c7c992..9748c93 100644 --- a/ResizableLib/ResizablePage.h +++ b/ResizableLib/ResizablePage.h @@ -36,8 +36,8 @@ class CResizablePage : public CPropertyPage, public CResizableLayout, // Construction public: CResizablePage(); - CResizablePage(UINT nIDTemplate, UINT nIDCaption = 0); - CResizablePage(LPCTSTR lpszTemplateName, UINT nIDCaption = 0); + explicit CResizablePage(UINT nIDTemplate, UINT nIDCaption = 0); + explicit CResizablePage(LPCTSTR lpszTemplateName, UINT nIDCaption = 0); // Attributes public: @@ -62,7 +62,7 @@ class CResizablePage : public CPropertyPage, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizablePageEx.h b/ResizableLib/ResizablePageEx.h index c4240f6..a16b1af 100644 --- a/ResizableLib/ResizablePageEx.h +++ b/ResizableLib/ResizablePageEx.h @@ -36,8 +36,8 @@ class CResizablePageEx : public CPropertyPageEx, public CResizableLayout, // Construction public: CResizablePageEx(); - CResizablePageEx(UINT nIDTemplate, UINT nIDCaption = 0, UINT nIDHeaderTitle = 0, UINT nIDHeaderSubTitle = 0); - CResizablePageEx(LPCTSTR lpszTemplateName, UINT nIDCaption = 0, UINT nIDHeaderTitle = 0, UINT nIDHeaderSubTitle = 0); + explicit CResizablePageEx(UINT nIDTemplate, UINT nIDCaption = 0, UINT nIDHeaderTitle = 0, UINT nIDHeaderSubTitle = 0); + explicit CResizablePageEx(LPCTSTR lpszTemplateName, UINT nIDCaption = 0, UINT nIDHeaderTitle = 0, UINT nIDHeaderSubTitle = 0); // Attributes public: @@ -62,7 +62,7 @@ class CResizablePageEx : public CPropertyPageEx, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizableSheet.h b/ResizableLib/ResizableSheet.h index e4270c4..3645091 100644 --- a/ResizableLib/ResizableSheet.h +++ b/ResizableLib/ResizableSheet.h @@ -38,8 +38,8 @@ class CResizableSheet : public CPropertySheet, public CResizableLayout, // Construction public: CResizableSheet(); - CResizableSheet(UINT nIDCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0); - CResizableSheet(LPCTSTR pszCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0); + explicit CResizableSheet(UINT nIDCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0); + explicit CResizableSheet(LPCTSTR pszCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0); // Attributes private: @@ -96,7 +96,7 @@ class CResizableSheet : public CPropertySheet, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizableSheetEx.h b/ResizableLib/ResizableSheetEx.h index beb7fb5..6b21f01 100644 --- a/ResizableLib/ResizableSheetEx.h +++ b/ResizableLib/ResizableSheetEx.h @@ -38,9 +38,9 @@ class CResizableSheetEx : public CPropertySheetEx, public CResizableLayout, // Construction public: CResizableSheetEx(); - CResizableSheetEx(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0, + explicit CResizableSheetEx(UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0, HBITMAP hbmWatermark = NULL, HPALETTE hpalWatermark = NULL, HBITMAP hbmHeader = NULL); - CResizableSheetEx(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0, + explicit CResizableSheetEx(LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0, HBITMAP hbmWatermark = NULL, HPALETTE hpalWatermark = NULL, HBITMAP hbmHeader = NULL); // Attributes @@ -103,7 +103,7 @@ class CResizableSheetEx : public CPropertySheetEx, public CResizableLayout, virtual CWnd* GetResizableWnd() const { // make the layout know its parent window - return CWnd::FromHandle(m_hWnd); + return CWnd::FromHandlePermanent(m_hWnd); }; // Generated message map functions diff --git a/ResizableLib/ResizableState.cpp b/ResizableLib/ResizableState.cpp index 2a8d119..e0600b7 100644 --- a/ResizableLib/ResizableState.cpp +++ b/ResizableLib/ResizableState.cpp @@ -50,7 +50,7 @@ CString CResizableState::m_sDefaultStorePath(_T("ResizableState")); * Static function to set the default path used to store state information. * This path is used to initialize all the instances of this class. * @sa GetDefaultStateStore GetStateStore SetStateStore - * + * * @param szPath String that specifies the new path to be set */ void CResizableState::SetDefaultStateStore(LPCTSTR szPath) @@ -63,7 +63,7 @@ void CResizableState::SetDefaultStateStore(LPCTSTR szPath) * information. * This path is used to initialize all the instances of this class. * @sa SetDefaultStateStore GetStateStore SetStateStore - * + * * @return The return value is a string that specifies the current path */ LPCTSTR CResizableState::GetDefaultStateStore() @@ -75,7 +75,7 @@ LPCTSTR CResizableState::GetDefaultStateStore() * This function sets the path used to store state information by * the current instance of the class. * @sa GetStateStore GetDefaultStateStore SetDefaultStateStore - * + * * @param szPath String that specifies the new path to be set */ void CResizableState::SetStateStore(LPCTSTR szPath) @@ -87,10 +87,10 @@ void CResizableState::SetStateStore(LPCTSTR szPath) * This function retrieves the path used to store state information by * the current instance of the class. * @sa SetStateStore GetDefaultStateStore SetDefaultStateStore - * + * * @return The return value is a string that specifies the current path */ -LPCTSTR CResizableState::GetStateStore() +LPCTSTR CResizableState::GetStateStore() const { return m_sStorePath; } @@ -101,10 +101,10 @@ LPCTSTR CResizableState::GetStateStore() * The base implementation uses the application profile to persist state * information, but this function can be overridden to implement * different methods. - * + * * @param szId String that identifies the stored settings * @param szState String that represents the state information to store - * + * * @return The return value is @a TRUE if settings have been successfully * stored, @a FALSE otherwise. */ @@ -119,10 +119,10 @@ BOOL CResizableState::WriteState(LPCTSTR szId, LPCTSTR szState) * The base implementation uses the application profile to persist state * information, but this function can be overridden to implement * different methods. - * + * * @param szId String that identifies the stored settings * @param rsState String to be filled with the retrieved state information - * + * * @return The return value is @a TRUE if settings have been successfully * retrieved, @a FALSE otherwise. */ diff --git a/ResizableLib/ResizableState.h b/ResizableLib/ResizableState.h index a60b340..01aeb61 100644 --- a/ResizableLib/ResizableState.h +++ b/ResizableLib/ResizableState.h @@ -36,31 +36,31 @@ * be set to either the Registry or an INI File. Other storing methods * can be implemented in derived classes. */ -class CResizableState +class CResizableState { static CString m_sDefaultStorePath; CString m_sStorePath; protected: - + //! @brief Get default path where state is stored static LPCTSTR GetDefaultStateStore(); - + //! @brief Set default path where state is stored static void SetDefaultStateStore(LPCTSTR szPath); //! @brief Get current path where state is stored - LPCTSTR GetStateStore(); - + LPCTSTR GetStateStore() const; + //! @brief Set current path where state is stored void SetStateStore(LPCTSTR szPath); //! @name Overridables //@{ - + //! @brief Read state information virtual BOOL ReadState(LPCTSTR szId, CString& rsState); - + //! @brief Write state information virtual BOOL WriteState(LPCTSTR szId, LPCTSTR szState); diff --git a/ResizableLib/ResizableWndState.cpp b/ResizableLib/ResizableWndState.cpp index d290213..6da0eff 100644 --- a/ResizableLib/ResizableWndState.cpp +++ b/ResizableLib/ResizableWndState.cpp @@ -40,7 +40,7 @@ CResizableWndState::~CResizableWndState() // depending on your application settings #define PLACEMENT_ENT _T("WindowPlacement") -#define PLACEMENT_FMT _T("%d,%d,%d,%d,%d,%d,%d,%d") +#define PLACEMENT_FMT _T("%ld,%ld,%ld,%ld,%u,%u,%ld,%ld") /*! * This function saves the current window position and size using the base @@ -49,10 +49,10 @@ CResizableWndState::~CResizableWndState() * @sa CResizableState::WriteState * @note Window coordinates are in the form used by the system functions * GetWindowPlacement and SetWindowPlacement. - * + * * @param pszName String that identifies stored settings * @param bRectOnly Flag that specifies wether to ignore min/max state - * + * * @return Returns @a TRUE if successful, @a FALSE otherwise */ BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly) @@ -64,7 +64,7 @@ BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly) wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp)) return FALSE; - + // use workspace coordinates RECT& rc = wp.rcNormalPosition; @@ -91,10 +91,10 @@ BOOL CResizableWndState::SaveWindowRect(LPCTSTR pszName, BOOL bRectOnly) * @sa CResizableState::WriteState * @note Window coordinates are in the form used by the system functions * GetWindowPlacement and SetWindowPlacement. - * + * * @param pszName String that identifies stored settings * @param bRectOnly Flag that specifies wether to ignore min/max state - * + * * @return Returns @a TRUE if successful, @a FALSE otherwise */ BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly) @@ -105,7 +105,7 @@ BOOL CResizableWndState::LoadWindowRect(LPCTSTR pszName, BOOL bRectOnly) id = CString(pszName) + PLACEMENT_ENT; if (!ReadState(id, data)) // never saved before return FALSE; - + ZeroMemory(&wp, sizeof(WINDOWPLACEMENT)); wp.length = sizeof(WINDOWPLACEMENT); if (!GetResizableWnd()->GetWindowPlacement(&wp))