Click here to Skip to main content
12,445,274 members (51,491 online)
Click here to Skip to main content

Stats

22.8K views
2.5K downloads
30 bookmarked
Posted

Improve Zooming with Enhanced Mouse Wheels

, 19 Oct 2011 CPOL
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)

Share

About the Author

Stephen H Davis
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.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160811.3 | Last Updated 19 Oct 2011
Article Copyright 2011 by Stephen H Davis
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid