Click here to Skip to main content
12,448,164 members (71,062 online)
Click here to Skip to main content

Stats

1.2M views
27.6K downloads
258 bookmarked
Posted

ResizableLib

, 15 Jun 2004 CPOL
A set of classes to ease the development of resizable windows with MFC
ResizableDialog
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
bitmap1.bmp
Demo.ico
toolbar1.bmp
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.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
Demo.ico
DemoDoc.ico
Toolbar.bmp
ResizableLib
.cvsignore
Docs
CVS
Entries
Repository
Root
Release_Static
ResizableLib.lib
ResizableLib.dsp
ResizableLib.dsw
.cvsignore
ResizableLib.dsp
ResizableLib.dsw
ChangeLog
ResizableLib.dsp
ResizableLib.dsw
ResizableMsgSupport.inl
Doxyfile-include
Doxyfile
ResizableLib.dsp
ResizableLib.dsw
ResizableLib.dsp
ResizableLib.dsw
.cvsignore
ResizableProperties
Demo.dsp
Demo.dsw
Release_Static
Demo.exe
Demo.exe.manifest
res
Demo.ico
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
Technical Lead RoboTech srl
Italy Italy
Paolo began programming at the age of 9 with a glorious Olivetti M24 (i8086) and GW-BASIC, then he played a bit with Turbo C, Turbo Pascal and Assembly (using the MS-DOS Debug). Quick BASIC and Visual Basic shortly followed, until he learned C++ in College. He tought himself MFC and Windows programming, along with some DHTML and Javascript.

Always attracted by low-level programming and Assembly, he started to appreciate the joys of templates and STL while working for his Master Thesis. For seven months he was playing with airplanes and automatic control at the Unversity of Illinois at Urbana-Champaign, where he first met QNX and embedded systems.

In his job experience he learned Java to develop user interfaces and graphical editors, and re-discovered the Eclipse IDE that he had used in its early versions with the QNX SDK. He also deepened his knowledge of Linux and embedded systems, microcontrollers firmware and embedded voice recognition, while also practicing electronics design.

He graduated in Computer Engineering (Ingegneria informatica) at the University of Pisa, Italy, in December 2003. Currently working for an edutainment robotics company (www.robotechsrl.com).

He lives in Peccioli (Pisa) and Follonica (GR), Italy.

You may also be interested in...

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