Click here to Skip to main content
15,885,537 members
Articles / Desktop Programming / WPF

Improve Zooming with Enhanced Mouse Wheels

Rate me:
Please Sign up or sign in to vote.
4.65/5 (7 votes)
19 Oct 2011CPOL6 min read 43.8K   4K   33  
How to give your users a better zooming experience with High Resolution Mouse Wheels.
// HiResScrollWheelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "HiResScrollWheel.h"
#include "HiResScrollWheelDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CHiResScrollWheelDlg dialog




CHiResScrollWheelDlg::CHiResScrollWheelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHiResScrollWheelDlg::IDD, pParent)
	, m_nWheelDelta(15)
	, m_nTimeDelta(8)
	, m_nEventsPerClick(8)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CHiResScrollWheelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_nWheelDelta);
	DDV_MinMaxUInt(pDX, m_nWheelDelta, 1, 240);
	DDX_Text(pDX, IDC_EDIT2, m_nTimeDelta);
	DDV_MinMaxUInt(pDX, m_nTimeDelta, 2, 1000);
	DDX_Text(pDX, IDC_EDIT3, m_nEventsPerClick);
	DDV_MinMaxUInt(pDX, m_nEventsPerClick, 1, 240);
}

BEGIN_MESSAGE_MAP(CHiResScrollWheelDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT1, &CHiResScrollWheelDlg::OnEnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, &CHiResScrollWheelDlg::OnEnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT3, &CHiResScrollWheelDlg::OnEnChangeEdit3)
	ON_BN_CLICKED(IDC_APPLY, &CHiResScrollWheelDlg::OnBnClickedApply)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


// CHiResScrollWheelDlg message handlers

__declspec( dllimport ) void SetParameters(int x1, int x2, int x3);

BOOL CHiResScrollWheelDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	SetParameters((int)m_nWheelDelta,(int)m_nTimeDelta,(int)m_nEventsPerClick) ;
	GetDlgItem(IDC_APPLY)->EnableWindow(0) ;		
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CHiResScrollWheelDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CHiResScrollWheelDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CHiResScrollWheelDlg::OnEnChangeEdit1()
{
	GetDlgItem(IDC_APPLY)->EnableWindow(1) ;		
}


void CHiResScrollWheelDlg::OnEnChangeEdit2()
{
	GetDlgItem(IDC_APPLY)->EnableWindow(1) ;		
}

void CHiResScrollWheelDlg::OnEnChangeEdit3()
{
	GetDlgItem(IDC_APPLY)->EnableWindow(1) ;		
}

void CHiResScrollWheelDlg::OnBnClickedApply()
{
	if (UpdateData()) {
		// data validated
		SetParameters((int)m_nWheelDelta,(int)m_nTimeDelta,(int)m_nEventsPerClick) ;
		GetDlgItem(IDC_APPLY)->EnableWindow(0) ;		
	}
}

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
Software Developer (Senior) Logitech Corporation
United States United States
Stephen lives in Fremont, CA with his wife and daughter and has programmed in C and C++ for a very long time.

Comments and Discussions