Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

3D Thermometer Control

, 2 Feb 2007
3D Thermometer Control Drawn with GDI Plus
thermometerctrltest_app.zip
ThermometerCtrlTest.exe
thermometerctrltest_src.zip
ThermometerCtrlTest
ThermometerCtrlTest.aps
ThermometerCtrlTest.ico
ThermometerCtrlTest.manifest
ThermometerCtrlTest.ncb
ThermometerCtrlTest.suo
// MainDlg.cpp : implementation file
#include "stdafx.h"
#include "ThermometerCtrlTest.h"
#include "MainDlg.h"
#include ".\maindlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDC_CHECKF, OnBnClickedCheckf)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER, OnNMReleasedcaptureSlider)
END_MESSAGE_MAP()

CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMainDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

BOOL CMainDlg::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

	// Setup thermometer control
	m_TempCtrl.SubclassDlgItem(IDC_TEMP, this);

	// Setup slider
	CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER);
	ASSERT(pSlider);
	pSlider->SetRange(0, 140);
	pSlider->SetPos(20);

	// Fahrenheit units are default
	((CButton*)GetDlgItem(IDC_CHECKF))->SetCheck(1);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMainDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	if(nSBCode != SB_ENDSCROLL)
	{
		if((pScrollBar) && (pScrollBar->GetDlgCtrlID() == IDC_SLIDER))
		{
			int iPos = (int)(nPos - 20);
			m_TempCtrl.SetPos(iPos);
		}
	}

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CMainDlg::OnNMReleasedcaptureSlider(NMHDR *pNMHDR, LRESULT *pResult)
{
	CSliderCtrl* pSlider = (CSliderCtrl*)GetDlgItem(IDC_SLIDER);
	ASSERT(pSlider);
	int iPos = (int)(pSlider->GetPos() - 20);
	m_TempCtrl.SetPos(iPos);

	*pResult = 0;
}

void CMainDlg::OnBnClickedCheckf()
{
	BOOL bCheck = ((CButton*)GetDlgItem(IDC_CHECKF))->GetCheck();
	m_TempCtrl.SetDisplayFahrenheit(bCheck);
	m_TempCtrl.Invalidate();
}


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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

JJMatthews
Software Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 2 Feb 2007
Article Copyright 2007 by JJMatthews
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid