Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC

The Ultimate Toolbox Home Page

Rate me:
Please Sign up or sign in to vote.
4.97/5 (141 votes)
25 Aug 2007CPOL13 min read 3.2M   91.4K   476  
The Ultimate Toolbox is now Open Source
// ScaleRollupDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dibmanager.h"
#include "mainfrm.h"
#include "ScaleRollupDlg.h"

#include <math.h>

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

/////////////////////////////////////////////////////////////////////////////
// CScaleRollupDlg dialog


CScaleRollupDlg::CScaleRollupDlg(CWnd* pParent /*=NULL*/)
	: COXRollup(CScaleRollupDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScaleRollupDlg)
	m_nScaledHeight = 0;
	m_nScaledWidth = 0;
	m_nZoomLevel = 0;
	//}}AFX_DATA_INIT
	m_nOrigHeight=0;
	m_nOrigWidth=0;
}


void CScaleRollupDlg::DoDataExchange(CDataExchange* pDX)
{
	COXRollup::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScaleRollupDlg)
	DDX_Control(pDX, IDC_ZOOM_LEVEL, m_ctlZoomLevel);
	DDX_Control(pDX, IDC_SPIN_ZOOM_LEVEL, m_ctlSpinZoom);
	DDX_Control(pDX, IDC_PICTURE, m_ctlPicture);
	DDX_Text(pDX, IDC_SCALED_HEIGHT, m_nScaledHeight);
	DDX_Text(pDX, IDC_SCALED_WIDTH, m_nScaledWidth);
	DDX_Text(pDX, IDC_ZOOM_LEVEL, m_nZoomLevel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScaleRollupDlg, COXRollup)
	//{{AFX_MSG_MAP(CScaleRollupDlg)
	ON_BN_CLICKED(IDC_BUTTON_APPLY, OnButtonApply)
	ON_EN_CHANGE(IDC_ZOOM_LEVEL, OnChangeZoomLevel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScaleRollupDlg message handlers

void CScaleRollupDlg::OnButtonApply() 
{
	// TODO: Add your control notification handler code here
	
	if(m_nZoomLevel<ID_MIN_ZOOM_LEVEL)
	{
		m_nZoomLevel=ID_MIN_ZOOM_LEVEL;
		UpdateData(FALSE);
	}


	// notify current recipient window 
	// that we have to change zoom level
	RUpdateData(TRUE);
	Send2MR(ID_APPLY);

	ShowControls();
}

void CScaleRollupDlg::OnChangeZoomLevel() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function to send the EM_SETEVENTMASK message to the control
	// with the ENM_CHANGE flag ORed into the lParam mask.
	
	// TODO: Add your control notification handler code here
	
	UpdateData(TRUE);

	ShowControls();
}

BOOL CScaleRollupDlg::OnInitDialog() 
{
	COXRollup::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	// Set the COXSpinCtrl object, which is mapped to a common Spin Control.
	m_ctlSpinZoom.SetBuddy(&m_ctlZoomLevel);
	m_ctlSpinZoom.SetRange(ID_MIN_ZOOM_LEVEL,ID_MAX_ZOOM_LEVEL);
	m_ctlSpinZoom.SetPos(m_nZoomLevel);

	// Set a default COXSpinCtrl method of delta value computation (Delta pixel = Delta value).
	m_ctlSpinZoom.SetComputationMethod(OX_SPIN_DELTA_PIXEL_IS_DELTA_VALUE);

	UpdateData(FALSE);

	ShowControls();

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

void CScaleRollupDlg::ShowControls() 
{
	if(m_nZoomLevel>ID_MAX_ZOOM_LEVEL)
		m_nZoomLevel=ID_MAX_ZOOM_LEVEL;

	CRect rectPicture, rectNewPicture;
	CPoint ptPictureCenter;

	m_nScaledWidth=((long)m_nOrigWidth*(long)m_nZoomLevel)/(100L);
	m_nScaledHeight=((long)m_nOrigHeight*(long)m_nZoomLevel)/(100L);

	m_ctlPicture.GetWindowRect(&rectPicture);
	ScreenToClient(&rectPicture);
	
	ptPictureCenter.x=rectPicture.left+rectPicture.Width()/2;
	ptPictureCenter.y=rectPicture.top+rectPicture.Height()/2;

	// we chose this formula because it let the picture control
	// to go from 10% to 1000%
	int nPictureWidth=(3*(int)sqrt((float)m_nZoomLevel)-(int)sqrt((float)m_nZoomLevel)/2)*2;
	
	rectNewPicture.left=ptPictureCenter.x-nPictureWidth/2;
	rectNewPicture.top=ptPictureCenter.y-nPictureWidth/2;
	rectNewPicture.right=rectNewPicture.left+nPictureWidth;
	rectNewPicture.bottom=rectNewPicture.top+nPictureWidth;

	if(rectNewPicture.left-rectPicture.left!=0)
	{
		m_ctlPicture.MoveWindow(rectNewPicture.left, rectNewPicture.top, 
			rectNewPicture.Width(), rectNewPicture.Height());
	}

	UpdateData(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)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions