>Counter<
1 Start


This is the final program of the counter, if you want to have the same like this, then lets start step by step
--------------------------------------------------------------------------------------------------------

• Create a MFC project named Counter

• Make sure that you have chosen the Dialog-Type


• Now you have to insert some objects into your new Dialog-window. For this you can use the toolbox one the left side.


• Insert one Edit Control, 6 Buttons, a Slider Control and a Progress Control


• Name Button1 Plus and Button2 Minus and also the ID into IDC_Plus or IDC_Minus


• Delete Name of Button 4, 5 and 6

• Rename the ID’s of this Buttons with IDC_But_Digh, IDC_But_Digz, IDC_But_Dige


• Do a Right-click on the Edit-Control and choose “add variable”

• Choose the Category “value”, the variable-type “int” and name it “iCount”


• Do a right –click on the Progress-Control and choose “add variable”

• Name only the variable “m_progress1” and let the other settings how they are

• Do another Right-Click on the Slider and do the same as before

• Name the variable “m_slider1”

• Go in the “Sample CounterDlg.cpp” and search the OnInitDialog

• Add under the “// TODO: Add extra initialization here“


2 Now we start to programm the Plus and Minus Features

• Do a Double-click on the Plus-Button, so the Program creates a new Message

• In the Message of the Button you write:


• Now make a Double-click on the Minus-button

• Write the same thing in the Message as in the Plus-Button but you must write instead of “iCount++;” “if(iCount>=1)iCount--;”: so the programm decreases iCount until it is zero
3 On Released Capture

• After this make a Right-click on the Slider and choose the eventmanager

• Add her a new event with Releasedcapture

• “iCount=m_slider1.GetPos();”: so you load the value from the slider in to iCount

• After you add “m_progress1.SetPos(iCount);“ and „UpdateData(false);“

• So if you move the slider the program will update the values


4 Add Bitmaps

• Click on the Buttons for the Bitmaps

• Change now in the property the User-interface to true

• Draw the Number-Bitmaps in the resources-window

• After this write the following things so the program loads at the beginning the zero-Bitmap in the Buttons

• Do a Right-Click and choose “Add Resource”

• Choose in the opening window “Bitmap”

• The program creates a new Bitmap

• Now you can draw your Number-Bitmap


• For a new Bitmap you have to make a Right-click and choose “add Bitmap”

• Add in the Plus and in the Minus Under-program

5 Change Bitmaps

• To add the bitmaps if you click on the Plus-Button you have to add this

6 Timer
• Now we want add a Timer so the Bitmaps change also if you change the Slider

• Click now over the settings of the things on the Symbol for the notice



• In the appearing event you add the following lines and then the same as before to change the buttons



7 Autocounter

• Now we can add a auto counter

• The Button3 you can name Start/Stop so you can use it to start or stop the auto-counter

• Now make a double-Click on this Button

• Add in the event the following lines



• Add also in the Timer this so the program accelerates his timer every time it gets zero



• Under this lines write also the lines for the bitmaps

8 The complete program
SampleCounterDlg.cpp


// Sample CounterDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Sample Counter.h"
#include "Sample CounterDlg.h"
#include ".\sample counterdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

int slidernew, sliderold;
int xx,enew,eold,znew,zold,hnew,hold;
int yy,zz=100,aa=2,bb,cc;


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CSampleCounterDlg dialog



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

void CSampleCounterDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, iCount);
	DDX_Control(pDX, IDC_PROGRESS1, m_progress1);
	DDX_Control(pDX, IDC_SLIDER1, m_slider1);
}

BEGIN_MESSAGE_MAP(CSampleCounterDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_Plus, OnBnClickedPlus)
	ON_BN_CLICKED(IDC_Minus, OnBnClickedMinus)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnNMReleasedcaptureSlider1)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUT_Start, OnBnClickedButStart)
END_MESSAGE_MAP()


// CSampleCounterDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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

	// TODO: Add extra initialization here
	m_progress1.SetRange(0,999);  //Dimensions the Progress-control
	m_slider1.SetRange(0,999);    //Dimensions the Slider
	m_progress1.SetPos(iCount);   //sets the Progress-control on the value of iCount
	UpdateData(false);//Puts out the values
	SetTimer(1,10,0);
	

	VERIFY(m_bmpdigh.SubclassDlgItem(IDC_But_Digh, this));
	VERIFY(m_bmpdigz.SubclassDlgItem(IDC_But_Digz, this));
	VERIFY(m_bmpdige.SubclassDlgItem(IDC_But_Dige, this));

	m_bmpdigh.LoadBitmaps(IDB_DIG10); 
	m_bmpdigh.Invalidate();
	m_bmpdigz.LoadBitmaps(IDB_DIG10); 
	m_bmpdigz.Invalidate();
	m_bmpdige.LoadBitmaps(IDB_DIG10); 
	m_bmpdige.Invalidate();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSampleCounterDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CSampleCounterDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast(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 CSampleCounterDlg::OnQueryDragIcon()
{
	return static_cast(m_hIcon);
}



void CSampleCounterDlg::OnBnClickedPlus()
{
	UpdateData(true);
	if (iCount>999)iCount=998;
	if (iCount<999)iCount++;
	m_progress1.SetPos(iCount);
	m_slider1.SetPos(iCount);
	UpdateData(false);


// =====For the units====
	enew = (iCount % 10);

	switch(enew)
 {
 case 0: m_bmpdige.LoadBitmaps(IDB_DIG10); break;   //if enew=0 the program draws the Zero Bitmap
 case 1: m_bmpdige.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdige.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdige.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdige.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdige.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdige.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdige.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdige.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdige.LoadBitmaps(IDB_DIG9); break;
 } 

 // =====For the tens====
  xx = iCount/10;   // 256/10 = 25
  znew = (xx % 10);  
  
 switch(znew)
 {
 case 0: m_bmpdigz.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigz.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigz.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigz.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigz.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigz.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigz.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigz.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigz.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigz.LoadBitmaps(IDB_DIG9); break;
 } 
 // ====For the hundreds====
 xx = iCount/100;
 hnew = (xx % 10);  
 switch(hnew)
 {
 case 0: m_bmpdigh.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigh.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigh.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigh.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigh.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigh.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigh.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigh.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigh.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigh.LoadBitmaps(IDB_DIG9); break;
 } 
 if (enew!=eold) m_bmpdige.Invalidate();  // redraws the Buttons
 if (znew!=zold) m_bmpdigz.Invalidate();
 if (hnew!=hold) m_bmpdigh.Invalidate();

 eold=enew;
 zold=znew;
 hold=hnew;

	
}

void CSampleCounterDlg::OnBnClickedMinus()
{
	UpdateData(true);
	if (iCount>1000)iCount=1000;
	if (iCount>0)iCount--;
	m_progress1.SetPos(iCount);
	m_slider1.SetPos(iCount);
	UpdateData(false);

		enew = (iCount % 10);

	switch(enew)
 {
 case 0: m_bmpdige.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdige.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdige.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdige.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdige.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdige.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdige.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdige.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdige.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdige.LoadBitmaps(IDB_DIG9); break;
 } 

  xx = iCount/10;   // 256/10 = 25
  znew = (xx % 10);  
  
 switch(znew)
 {
 case 0: m_bmpdigz.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigz.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigz.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigz.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigz.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigz.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigz.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigz.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigz.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigz.LoadBitmaps(IDB_DIG9); break;
 } 

 xx = iCount/100;
  
  hnew = (xx % 10);  
  
 switch(hnew)
 {
 case 0: m_bmpdigh.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigh.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigh.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigh.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigh.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigh.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigh.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigh.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigh.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigh.LoadBitmaps(IDB_DIG9); break;
 } 
 if (enew!=eold) m_bmpdige.Invalidate();
 if (znew!=zold) m_bmpdigz.Invalidate();
 if (hnew!=hold) m_bmpdigh.Invalidate();
 
  eold=enew;
  zold=znew;
  hold=hnew;
	
}

void CSampleCounterDlg::OnNMReleasedcaptureSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
	
	*pResult = 0;
	iCount=m_slider1.GetPos();
	m_progress1.SetPos(iCount);
	UpdateData(false);
}

void CSampleCounterDlg::OnTimer(UINT nIDEvent)
{
	
if (nIDEvent==1)  // so you can use more than one Timer
   {
	sliderold=iCount;
	slidernew=m_slider1.GetPos();
	if (slidernew!=sliderold)
	{
		m_progress1.SetPos(slidernew);
		iCount=slidernew;
		UpdateData(false);
		sliderold=slidernew;
	

	enew = (iCount % 10);

	switch(enew)
 {
 case 0: m_bmpdige.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdige.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdige.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdige.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdige.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdige.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdige.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdige.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdige.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdige.LoadBitmaps(IDB_DIG9); break;
 } 

  xx = iCount/10;   // 256/10 = 25
  znew = (xx % 10);  
  
 switch(znew)
 {
 case 0: m_bmpdigz.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigz.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigz.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigz.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigz.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigz.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigz.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigz.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigz.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigz.LoadBitmaps(IDB_DIG9); break;
 } 

 xx = iCount/100;
  
  hnew = (xx % 10);  
  
 switch(hnew)
 {
 case 0: m_bmpdigh.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigh.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigh.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigh.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigh.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigh.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigh.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigh.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigh.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigh.LoadBitmaps(IDB_DIG9); break;
 } 
 if (enew!=eold) m_bmpdige.Invalidate();
 if (znew!=zold) m_bmpdigz.Invalidate();
 if (hnew!=hold) m_bmpdigh.Invalidate();
 
  eold=enew;
  zold=znew;
  hold=hnew;
	}
   }
   if (nIDEvent==2)
   {
	   if (cc==0)
	   {
	   if(bb==1)
	   {
	   if (yy==0)
	   {
	   UpdateData(true);
	   if (iCount<999) iCount++;
	   m_progress1.SetPos(iCount);
	   m_slider1.SetPos(iCount);
	   UpdateData(false);
	   if(iCount==999)yy=1;
	   }
	   if (yy==1)
	   {
	   UpdateData(true);
	   if (iCount>0) iCount--;
	   m_progress1.SetPos(iCount);
	   m_slider1.SetPos(iCount);
	   UpdateData(false);
	   if(iCount==0){yy=0;zz-=20;SetTimer(2,zz,0);}
	   
	   }
	   enew = (iCount % 10);
	   

	switch(enew)
 {
 case 0: m_bmpdige.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdige.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdige.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdige.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdige.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdige.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdige.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdige.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdige.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdige.LoadBitmaps(IDB_DIG9); break;
 } 

  xx = iCount/10;   // 256/10 = 25
  znew = (xx % 10);  
  
 switch(znew)
 {
 case 0: m_bmpdigz.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigz.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigz.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigz.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigz.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigz.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigz.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigz.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigz.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigz.LoadBitmaps(IDB_DIG9); break;
 } 

 xx = iCount/100;
  
  hnew = (xx % 10);  
  
 switch(hnew)
 {
 case 0: m_bmpdigh.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigh.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigh.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigh.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigh.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigh.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigh.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigh.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigh.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigh.LoadBitmaps(IDB_DIG9); break;
 } 
 if (enew!=eold) m_bmpdige.Invalidate();
 if (znew!=zold) m_bmpdigz.Invalidate();
 if (hnew!=hold) m_bmpdigh.Invalidate();
 
  eold=enew;
  zold=znew;
  hold=hnew;
   }
	
}
	   if (nIDEvent==2)
   {
	   if (cc==0)
	   {
	   if(bb==1)
	   {
	   if (yy==0)
	   {
	   UpdateData(true);
	   if (iCount<999) iCount++;
	   m_progress1.SetPos(iCount);
	   m_slider1.SetPos(iCount);
	   UpdateData(false);
	   if(iCount==999)yy=1;
	   }
	   if (yy==1)
	   {
	   UpdateData(true);
	   if (iCount>0) iCount--;
	   m_progress1.SetPos(iCount);
	   m_slider1.SetPos(iCount);
	   UpdateData(false);
	   if(iCount==0)
	   {
		   yy=0;
		   zz-=20;
		   if(zz==0)zz=100; 
		   SetTimer(2,zz,0);
	   }
	   }



	   enew = (iCount % 10);
	   

	switch(enew)
 {
 case 0: m_bmpdige.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdige.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdige.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdige.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdige.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdige.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdige.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdige.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdige.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdige.LoadBitmaps(IDB_DIG9); break;
 } 

  xx = iCount/10;   // 256/10 = 25
  znew = (xx % 10);  
  
 switch(znew)
 {
 case 0: m_bmpdigz.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigz.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigz.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigz.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigz.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigz.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigz.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigz.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigz.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigz.LoadBitmaps(IDB_DIG9); break;
 } 

 xx = iCount/100;
 hnew = (xx % 10);  
  
 switch(hnew)
 {
 case 0: m_bmpdigh.LoadBitmaps(IDB_DIG10); break;
 case 1: m_bmpdigh.LoadBitmaps(IDB_DIG1); break;
 case 2: m_bmpdigh.LoadBitmaps(IDB_DIG2); break;
 case 3: m_bmpdigh.LoadBitmaps(IDB_DIG3); break;
 case 4: m_bmpdigh.LoadBitmaps(IDB_DIG4); break;
 case 5: m_bmpdigh.LoadBitmaps(IDB_DIG5); break;
 case 6: m_bmpdigh.LoadBitmaps(IDB_DIG6); break;
 case 7: m_bmpdigh.LoadBitmaps(IDB_DIG7); break;
 case 8: m_bmpdigh.LoadBitmaps(IDB_DIG8); break;
 case 9: m_bmpdigh.LoadBitmaps(IDB_DIG9); break;
 } 


 if (enew!=eold) m_bmpdige.Invalidate();
 if (znew!=zold) m_bmpdigz.Invalidate();
 if (hnew!=hold) m_bmpdigh.Invalidate();
 
  eold=enew;
  zold=znew;
  hold=hnew;
   }
	
}
   }}
	CDialog::OnTimer(nIDEvent);
}

void CSampleCounterDlg::OnBnClickedButStart()
{

	if (cc==0)    //Starts the Auto-counter
	{
	aa=(aa%2);
	switch(aa)
	{
	case 0: bb=1; break;
	case 1: bb=0; break;
	}
	aa++;
	}
	else cc=0;
		SetTimer(2,zz,0);   //Stops the Auto-counter
}



SampleCounterDlg.h



// Sample CounterDlg.h : header file
//

#pragma once
#include "afxcmn.h"


// CSampleCounterDlg dialog
class CSampleCounterDlg : public CDialog
{
// Construction
public:
	CSampleCounterDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_SAMPLECOUNTER_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()
public:
	int iCount;
	CProgressCtrl m_progress1;
	CSliderCtrl m_slider1;
	afx_msg void OnBnClickedPlus();
	afx_msg void OnBnClickedMinus();
	afx_msg void OnNMReleasedcaptureSlider1(NMHDR *pNMHDR, LRESULT *pResult);
	CBitmapButton m_bmpdigh, m_bmpdigz, m_bmpdige;
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnBnClickedButStart();
};
(); };