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

An LED Style display control and bar control

, 17 Jan 2000
A control to display time, floating point numbers or integers using an LED digital-style display
staticcounter_demo.zip
CStaticCounterEx
Release
StaticCounterExDemo.exe
RES
StaticCounterExDemo.ico
Test.psp
StaticCounterExDemo.clw
StaticCounterExDemo.dsp
StaticCounterExDemo.dsw
StaticCounterExDemo.stt
staticcounter_src.zip
// StaticCounterExDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StaticCounterExDemo.h"
#include "StaticCounterExDemoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStaticCounterExDemoDlg dialog

CStaticCounterExDemoDlg::CStaticCounterExDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CStaticCounterExDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStaticCounterExDemoDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CStaticCounterExDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStaticCounterExDemoDlg)
	DDX_Control(pDX, IDC_STATIC_4, m_stcDemo4);
	DDX_Control(pDX, IDC_STATIC_1, m_stcDemo1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CStaticCounterExDemoDlg, CDialog)
	//{{AFX_MSG_MAP(CStaticCounterExDemoDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaticCounterExDemoDlg message handlers

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Function Header
BOOL CStaticCounterExDemoDlg::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
	
	m_stcDemo2.Create("",WS_VISIBLE|SS_NOTIFY|WS_DLGFRAME, CStaticCounter::GetRect(IDC_STATIC_2, this),(CWnd*)this);
	m_stcDemo2.SetBlankPadding(11);
	m_stcDemo2.SetFormatString("%.2f");
	m_stcDemo2.SetPos(0.0f);

	m_stcDemo3.Create("",WS_VISIBLE|SS_NOTIFY|SS_SUNKEN, CStaticCounter::GetRect(IDC_STATIC_3, this),(CWnd*)this);
	m_stcDemo3.SetColours(RGB(255,255,255), RGB(0,0,100), RGB(0,0,150));
	m_stcDemo3.SetAllowInteraction(false);
	m_stcDemo3.SetFormatString("%.8d");
	m_stcDemo3.SetDrawFaded(false);

	m_stcDemo4.SetFormatString("%.2f");
	m_stcDemo4.SetBlankPadding(9);
	m_stcDemo4.SetColourFaded(RGB(40,40,40));
	m_stcDemo4.SetBarHeight();
	m_stcDemo4.SetColours( RGB(200,200,200), 0, RGB(150,0,0) );

	SetTimer(496, 10, NULL);
	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 CStaticCounterExDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CStaticCounterExDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Function Header
void CStaticCounterExDemoDlg::OnTimer(UINT nIDEvent) 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
	static float fCounter = 35;

	if ( ((fCounter+=0.01f)*22) >1000 ) fCounter=0;
	
	m_stcDemo1.SetPos( ((int)(fCounter*10))%100, true, 0, 100);
	m_stcDemo3.SetPos((int)(fCounter*40)%1000, true, 0, 1000);
	m_stcDemo4.SetPos(fCounter*22, true, 0, 1000);

	CDialog::OnTimer(nIDEvent);
}

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

Jason Troitsky

United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 18 Jan 2000
Article Copyright 2000 by Jason Troitsky
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid