Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

ResizableLib

, 15 Jun 2004
A set of classes to ease the development of resizable windows with MFC
resizabledialog_demo_1_4a.zip
ResizableDialog
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
bitmap1.bmp
Demo.ico
toolbar1.bmp
resizableformviewmdi_demo_1_4a.zip
ResizableFormViewMDI
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
Demo.ico
DemoDoc.ico
DemoDoc0.ico
DemoDoc1.ico
DemoDoc2.ico
resizableformviewsdi_demo_1_4a.zip
ResizableFormViewSDI
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
Demo.ico
DemoDoc.ico
Toolbar.bmp
resizablelib_1_1.zip
ResizableLib
.cvsignore
Docs
CVS
Entries
Repository
Root
Release_Static
ResizableLib.lib
ResizableLib.dsp
ResizableLib.dsw
resizablelib_1_2.zip
.cvsignore
ResizableLib.dsp
ResizableLib.dsw
resizablelib_1_3.zip
ChangeLog
ResizableLib.dsp
ResizableLib.dsw
ResizableMsgSupport.inl
resizablelib_1_4a.zip
Doxyfile-include
Doxyfile
ResizableLib.dsp
ResizableLib.dsw
resizablelib_src.zip
ResizableLib.dsp
ResizableLib.dsw
.cvsignore
resizableproperties_demo_1_4a.zip
ResizableProperties
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
Demo.ico
resizablewizard97_demo_1_4a.zip
ResizableWizard97
Release_Static
Wizard97.exe
Wizard97.exe.manifest
res
Baner16.bmp
Baner256.bmp
Water16.bmp
Water256.bmp
Wizard97.ico
Wizard97.dsp
Wizard97.dsw
// DemoView.cpp : implementation of the CDemoView class
//

#include "stdafx.h"
#include "Demo.h"

#include "DemoDoc.h"
#include "DemoView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDemoView

IMPLEMENT_DYNCREATE(CDemoView, CResizableFormView)

BEGIN_MESSAGE_MAP(CDemoView, CResizableFormView)
	//{{AFX_MSG_MAP(CDemoView)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDemoView construction/destruction

CDemoView::CDemoView()
	: CResizableFormView(CDemoView::IDD)
{
	//{{AFX_DATA_INIT(CDemoView)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CDemoView::~CDemoView()
{
}

void CDemoView::DoDataExchange(CDataExchange* pDX)
{
	CResizableFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDemoView)
	DDX_Control(pDX, IDC_ICON1, m_icon1);
	//}}AFX_DATA_MAP
}

void CDemoView::OnInitialUpdate()
{
	// complete initialization
	CResizableFormView::OnInitialUpdate();

	// use template size as min track size
	CRect rect(CPoint(0, 0), GetTotalSize());
	CalcWindowRect(rect, CWnd::adjustOutside);
	SetMinTrackSize(rect.Size());

	CheckRadioButton(IDC_RADIO1, IDC_RADIO2, IDC_RADIO1);

	// change icon and disable buttons
	m_icon1.SetIcon((HICON)::GetClassLong(GetParentFrame()->GetSafeHwnd(), GCL_HICON));
	if (GetParentFrame() != GetParent())
	{
		GetDlgItem(IDC_BUTTON1)->EnableWindow(FALSE);
		GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
	}
	else // only if parent is a frame (not for splitters)!
	{
		// these two lines are optional
		GetParentFrame()->RecalcLayout();
		ResizeParentToFit();
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDemoView diagnostics

#ifdef _DEBUG
void CDemoView::AssertValid() const
{
	CResizableFormView::AssertValid();
}

void CDemoView::Dump(CDumpContext& dc) const
{
	CResizableFormView::Dump(dc);
}

CDemoDoc* CDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDemoDoc)));
	return (CDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDemoView message handlers

void CDemoView::OnButton2() 
{
	FormViewToDialog();
	UpdateSizeGrip();
}

void CDemoView::OnButton1() 
{
	DialogToFormView();
	UpdateSizeGrip();
}

void CDemoView::FormViewToDialog()
{
	CWnd* pParent = GetParent();
	// estimate new window's size
	CRect rect;
	GetTotalClientRect(&rect);	// uses GetTotalSize()
	DWORD style = pParent->GetStyle() & ~WS_THICKFRAME | WS_DLGFRAME;
	::AdjustWindowRect(&rect, style, ::IsMenu(::GetMenu(pParent->GetSafeHwnd())));
	// change style and size
	pParent->ModifyStyle(WS_THICKFRAME, WS_DLGFRAME);
	pParent->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(),
		SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED);
	ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_FRAMECHANGED);
}

void CDemoView::DialogToFormView()
{
	CWnd* pParent = GetParent();
	// estimate new window's size
	CRect rect;
	GetTotalClientRect(&rect);	// uses GetTotalSize()
	DWORD style = pParent->GetStyle() & ~WS_DLGFRAME | WS_THICKFRAME|WS_CAPTION;
	::AdjustWindowRectEx(&rect, style, ::IsMenu(::GetMenu(pParent->GetSafeHwnd())),
		WS_EX_CLIENTEDGE);
	// change style and size
	pParent->ModifyStyle(WS_DLGFRAME, WS_THICKFRAME|WS_CAPTION);
	pParent->SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(),
		SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED);
	ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
}

void CDemoView::OnRadio3() 
{
	// scrollbars won't appear
	SetScaleToFitSize(GetTotalSize());
}

void CDemoView::OnRadio2() 
{
	// allow any size
	ResetMinTrackSize();
	// reactivate scrollbars
	SetScrollSizes(MM_TEXT, GetTotalSize());
}

void CDemoView::OnRadio1() 
{
	// use template size as min track size
	CRect rect(CPoint(0, 0), GetTotalSize());
	CalcWindowRect(rect, CWnd::adjustOutside);
	SetMinTrackSize(rect.Size());
	// reactivate scrollbars
	SetScrollSizes(MM_TEXT, GetTotalSize());
}

BOOL CDemoView::OnInitDialog() 
{
	CResizableFormView::OnInitDialog();
	
	// preset layout
	AddAnchor(IDC_STATIC2, TOP_LEFT);
	AddAnchor(IDC_EDIT1, TOP_LEFT, ANCHOR(40,100));
	AddAnchor(IDC_BUTTON1, BOTTOM_LEFT, ANCHOR(40,100));
	AddAnchor(IDC_BUTTON2, BOTTOM_LEFT, ANCHOR(40,100));
	AddAnchor(IDC_GROUP1, ANCHOR(40,0), BOTTOM_RIGHT);
	AddAnchor(IDC_COMBO1, ANCHOR(40,0), TOP_RIGHT);
	AddAnchor(IDC_RADIO1, ANCHOR(70,0), ANCHOR(70,0));
	AddAnchor(IDC_RADIO2, ANCHOR(70,0), ANCHOR(70,0));
	AddAnchor(IDC_RADIO3, ANCHOR(70,0), ANCHOR(70,0));
	AddAnchor(IDC_STATIC1, ANCHOR(40,0), BOTTOM_RIGHT);
	AddAnchor(IDC_ICON1, ANCHOR(40,0), ANCHOR(70,0));

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Paolo Messina
Software Developer RoboTech srl
Italy Italy
Paolo began programming at the age of 9 with a glorious 8086 and GW-BASIC, then he played a bit with C, ASM and Pascal. He tought himself MFC and Windows programming, to exploit his studies of C++. Always attracted by low-level programming and Assembly, he's beginning to appreciate the joys of templates and STL. At work he changed his mind about Java, discovered Eclipse IDE, and now think it's cool.
 
He lives in Follonica, Italy.
 
He has been abroad in the U.S. to work on his final thesis before graduating. For seven months he was playing with airplanes and automatic control at the Unversity of Illinois at Urbana-Champaign.
 
He graduated in Computer Science Engineering at the University of Pisa, Italy, in December 2003.
 
Currently working for an edutainment robotics company (www.robotechsrl.com).
Follow on   Google+

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 15 Jun 2004
Article Copyright 2001 by Paolo Messina
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid