- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# ResizableDialog.cpp

    00001 // ResizableDialog.cpp : implementation file
    00002 //
    00004 //
    00005 // Copyright (C) 2000-2002 by Paolo Messina
    00006 // (http://www.geocities.com/ppescher - ppescher@yahoo.com)
    00007 //
    00008 // The contents of this file are subject to the Artistic License (the "License").
    00009 // You may not use this file except in compliance with the License.
    00010 // You may obtain a copy of the License at:
    00011 // http://www.opensource.org/licenses/artistic-license.html
    00012 //
    00013 // If you find this code useful, credits would be nice!
    00014 //
    00016
    00017 #include "stdafx.h"
    00018 #include "ResizableDialog.h"
    00019
    00020 #ifdef _DEBUG
    00021 #define new DEBUG_NEW
    00022 #undef THIS_FILE
    00023 static char THIS_FILE[] = __FILE__;
    00024 #endif
    00025
    00027 // CResizableDialog
    00028
    00029 inline void CResizableDialog::PrivateConstruct()
    00030 {
    00031         m_bEnableSaveRestore = FALSE;
    00032         m_dwGripTempState = 1;
    00033 }
    00034
    00035 CResizableDialog::CResizableDialog()
    00036 {
    00037         PrivateConstruct();
    00038 }
    00039
    00040 CResizableDialog::CResizableDialog(UINT nIDTemplate, CWnd* pParentWnd)
    00041         : CCmdUIDialog(nIDTemplate, pParentWnd)
    00042 {
    00043         PrivateConstruct();
    00044 }
    00045
    00046 CResizableDialog::CResizableDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
    00047         : CCmdUIDialog(lpszTemplateName, pParentWnd)
    00048 {
    00049         PrivateConstruct();
    00050 }
    00051
    00052 CResizableDialog::~CResizableDialog()
    00053 {
    00054 }
    00055
    00056
    00057 BEGIN_MESSAGE_MAP(CResizableDialog, CCmdUIDialog)
    00058         //{{AFX_MSG_MAP(CResizableDialog)
    00059         ON_WM_GETMINMAXINFO()
    00060         ON_WM_SIZE()
    00061         ON_WM_DESTROY()
    00062         ON_WM_CREATE()
    00063         ON_WM_ERASEBKGND()
    00064         //}}AFX_MSG_MAP
    00065 END_MESSAGE_MAP()
    00066
    00067
    00069 // CResizableDialog message handlers
    00070
    00071 int CResizableDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
    00072 {
    00073         if (__super::OnCreate(lpCreateStruct) == -1)
    00074                 return -1;
    00075
    00076         // child dialogs don't want resizable border or size grip,
    00077         // nor they can handle the min/max size constraints
    00078         BOOL bChild = GetStyle() & WS_CHILD;
    00079
    00080         if (!bChild)
    00081         {
    00082                 // keep client area
    00083                 CRect rect;
    00084                 GetClientRect(&rect);
    00085                 // set resizable style
    00086                 ModifyStyle(DS_MODALFRAME, WS_POPUP | WS_THICKFRAME);
    00087                 // adjust size to reflect new style
    00088                 ::AdjustWindowRectEx(&rect, GetStyle(),
    00089                         ::IsMenu(GetMenu()->GetSafeHmenu()), GetExStyle());
    00090                 SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_FRAMECHANGED|
    00091                         SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREPOSITION);
    00092
    00093                 // set the initial size as the min track size
    00094                 SetMinTrackSize(rect.Size());
    00095         }
    00096
    00097         // create and init the size-grip
    00098         if (!CreateSizeGrip(!bChild))
    00099                 return -1;
    00100
    00101         return 0;
    00102 }
    00103
    00104 void CResizableDialog::OnDestroy()
    00105 {
    00106         if (m_bEnableSaveRestore)
    00107                 SaveWindowRect(m_sSection, m_bRectOnly);
    00108
    00109         // remove child windows
    00110         RemoveAllAnchors();
    00111
    00112         __super::OnDestroy();
    00113 }
    00114
    00115 void CResizableDialog::OnSize(UINT nType, int cx, int cy)
    00116 {
    00117         CWnd::OnSize(nType, cx, cy);
    00118
    00119         if (nType == SIZE_MAXHIDE || nType == SIZE_MAXSHOW)
    00120                 return;         // arrangement not needed
    00121
    00122         if (nType == SIZE_MAXIMIZED)
    00123                 HideSizeGrip(&m_dwGripTempState);
    00124         else
    00125                 ShowSizeGrip(&m_dwGripTempState);
    00126
    00127         // update grip and layout
    00128         UpdateSizeGrip();
    00129         ArrangeLayout();
    00130 }
    00131
    00132 void CResizableDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
    00133 {
    00134         MinMaxInfo(lpMMI);
    00135 }
    00136
    00137 // NOTE: this must be called after setting the layout
    00138 //       to have the dialog and its controls displayed properly
    00139 void CResizableDialog::EnableSaveRestore(LPCTSTR pszSection, BOOL bRectOnly)
    00140 {
    00141         m_sSection = pszSection;
    00142
    00143         m_bEnableSaveRestore = TRUE;
    00144         m_bRectOnly = bRectOnly;
    00145
    00146         // restore immediately
    00147         LoadWindowRect(pszSection, bRectOnly);
    00148 }
    00149
    00150
    00151 BOOL CResizableDialog::OnEraseBkgnd(CDC* pDC)
    00152 {
    00153         // Windows XP doesn't like clipping regions ...try this!
    00154         EraseBackground(pDC);
    00155         return TRUE;
    00156
    00157 /*      ClipChildren(pDC);      // old-method (for safety)
    00158
    00159         return CDialog::OnEraseBkgnd(pDC);
    00160 */
    00161 }