Click here to Skip to main content
12,076,727 members (46,803 online)
Click here to Skip to main content

Stats

1.1M views
27.2K downloads
257 bookmarked
Posted

ResizableLib

, 15 Jun 2004 CPOL
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
// SecondDialog.cpp : implementation file
//

#include "stdafx.h"
#include "demo.h"
#include "SecondDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSecondDialog dialog


CSecondDialog::CSecondDialog(CWnd* pParent /*=NULL*/)
	: CResizableDialog(CSecondDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSecondDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CSecondDialog::DoDataExchange(CDataExchange* pDX)
{
	CResizableDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSecondDialog)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSecondDialog, CResizableDialog)
	//{{AFX_MSG_MAP(CSecondDialog)
	ON_WM_CREATE()
	ON_COMMAND(ID_BUTTON1, OnButton1)
	ON_COMMAND(ID_BUTTON2, OnButton2)
	ON_COMMAND(ID_BUTTON3, OnButton3)
	ON_COMMAND(ID_BUTTON4, OnButton4)
	//}}AFX_MSG_MAP
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSecondDialog message handlers

BOOL CSecondDialog::OnInitDialog() 
{
	CResizableDialog::OnInitDialog();

	// move toolbar to its position
	// before adding it to the layout
	CSize size;
	CRect rect, rc;
	GetDlgItem(IDOK)->GetWindowRect(&rect);
	GetDlgItem(IDC_LINE1)->GetWindowRect(&rc);
	rect.left = rc.left;
	ScreenToClient(&rect);
	m_wndToolBar.GetToolBarCtrl().GetMaxSize(&size);
	rect.right = rect.left + size.cx;
	rect.bottom = rect.top + size.cy;

	m_wndToolBar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY);
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, 
		CWnd::reposDefault, NULL, rect);
	m_wndToolBar.SetWindowPos(&wndBottom,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);

	// set layout
	AddAnchor(IDC_PICTURE1, TOP_LEFT, ANCHOR(30,100));
	AddAnchor(IDC_STATIC1, ANCHOR(30,0), ANCHOR(80,100));
	AddAnchor(IDC_STATIC2, ANCHOR(80,0), BOTTOM_RIGHT);

	AddAnchor(IDC_LINE1, BOTTOM_LEFT, BOTTOM_RIGHT);
	AddAnchor(IDOK, BOTTOM_RIGHT);
	AddAnchor(IDCANCEL, BOTTOM_RIGHT);

	// these should be equivalent, as long as you leave the
	// default control ID for the toolbar in the Create() call
	//AddAnchor(AFX_IDW_TOOLBAR, BOTTOM_LEFT);
	AddAnchor(m_wndToolBar.GetSafeHwnd(), BOTTOM_LEFT);

	// allow any size
	ResetMinTrackSize();

	// enable transparent grip
	SetSizeGripBkMode(TRANSPARENT);

	return TRUE;  // return TRUE unless you set the focus to a control
}

int CSecondDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CResizableDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// create toolbar, with just buttons and no border
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_TRANSPARENT|TBSTYLE_FLAT) ||
		!m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}
	m_wndToolBar.SetBorders(0,0,0,0);
	// tooltips don't work! (see note below)

	return 0;
}

void CSecondDialog::OnButton1() 
{
	// set background color
	m_brushBack.DeleteObject();
	m_brushBack.CreateSolidBrush(RGB(250,200,200));
	Invalidate();

	// NOTE: for details on how you could put a toolbar in a dialog
	// box and use ON_UPDATE_COMMAND_UI, see KB article Q141751
	// "SAMPLE: Adding Control Bars to Dialog Boxes in MFC"
	// with the sample project DLGCBR32 and some hints
}

void CSecondDialog::OnButton2() 
{
	// set background color
	m_brushBack.DeleteObject();
	m_brushBack.CreateSolidBrush(RGB(200,200,250));
	Invalidate();
}

void CSecondDialog::OnButton3() 
{
	// set background color
	m_brushBack.DeleteObject();
	m_brushBack.CreateSolidBrush(RGB(190,250,190));
	Invalidate();
}

void CSecondDialog::OnButton4() 
{
	// set background color
	m_brushBack.DeleteObject();
	m_brushBack.CreateSolidBrush(RGB(250,250,180));
	Invalidate();
}

HBRUSH CSecondDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CResizableDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	LOGBRUSH logbr;
	if (m_brushBack.m_hObject != NULL &&
		m_brushBack.GetLogBrush(&logbr) == sizeof(LOGBRUSH))
	{
		pDC->SetBkColor(logbr.lbColor);
		return m_brushBack;
	}

	return hbr;
}

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.

At work 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. There 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...

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