Click here to Skip to main content
11,805,316 members (63,755 online)
Click here to Skip to main content
Add your own
alternative version

Progress Cell for Grid Control.

, 10 May 2004 51.5K 2.4K 38
A new cell progress-bar-like type for Chris Maunder's Grid Control.
// GridProgressCellDlg.cpp : implementation file
// Written by Iain Clarke  ( /

#include "stdafx.h"
#include "GridProgressCell.h"
#include "GridProgressCellDlg.h"

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

#include "GridCellProgress.h"

// CGridProgressCellDlg dialog

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

void CGridProgressCellDlg::DoDataExchange(CDataExchange* pDX)
	DDX_Control (pDX, IDC_GRID, m_Grid);
		// NOTE: the ClassWizard will add DDX and DDV calls here

BEGIN_MESSAGE_MAP(CGridProgressCellDlg, CDialog)

// CGridProgressCellDlg message handlers

BOOL CGridProgressCellDlg::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
	// TODO: Add extra initialization here
	m_Grid.SetColumnCount (1);
	m_Grid.SetRowCount (10);
	m_Grid.ExpandColumnsToFit ();

	CGridCellProgress *pProg;
	for (int n = 0; n < 10; n++)
		m_Grid.SetCellType (n, 0, RUNTIME_CLASS(CGridCellProgress));

	pProg = (CGridCellProgress *)m_Grid.GetCell (0,0);
	pProg->SetText ("One");
	pProg->SetPos (0);

	pProg = (CGridCellProgress *)m_Grid.GetCell (1,0);
	pProg->SetText ("Two");
	pProg->SetUpper (200);

	pProg = (CGridCellProgress *)m_Grid.GetCell (2,0);
	pProg->SetText ("Three");
	pProg->SetColor (RGB(0,255,0));
	pProg = (CGridCellProgress *)m_Grid.GetCell (3,0);
	pProg->SetText ("Four");
	pProg->EnablePercentage (FALSE);
	pProg = (CGridCellProgress *)m_Grid.GetCell (4,0);
	pProg->SetText ("Five - But\\a\\very\\long string\\will\\now\\follow,\\because\\I\\want\\it\\to.\\And\\another\\long\\string\\to.\\Phew,\\my\\fingers\\are\\tired.");
	pProg = (CGridCellProgress *)m_Grid.GetCell (5,0);
	pProg->SetText ("Six - But\\a\\very\\long string\\will\\now\\follow,\\because\\I\\want\\it\\to.\\And\\another\\long\\string\\to.\\Phew,\\my\\fingers\\are\\tired.");
	pProg->EnablePathCompaction (FALSE);
	pProg = (CGridCellProgress *)m_Grid.GetCell (6,0);
	pProg->SetText ("Seven");
	pProg = (CGridCellProgress *)m_Grid.GetCell (7,0);
	pProg->SetText ("Eight");
	pProg->SetColor (RGB(255,255,0));
	pProg = (CGridCellProgress *)m_Grid.GetCell (8,0);
	pProg->SetText ("Nine");

	pProg = (CGridCellProgress *)m_Grid.GetCell (9,0);
	pProg->SetText ("Ten");

	SetTimer (1, 100, 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 CGridProgressCellDlg::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;
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGridProgressCellDlg::OnQueryDragIcon()
	return (HCURSOR) m_hIcon;

void CGridProgressCellDlg::OnTimer(UINT nIDEvent) 
	CGridCellProgress *pProg;
	for (int n = 0; n < 10; n++)
		pProg = (CGridCellProgress *)m_Grid.GetCell (n,0);
		pProg->SetPos ( (pProg->GetPos () + 1) % (pProg->GetUpper ()+1) );


	m_Grid.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.


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


About the Author

Iain Clarke, Warrior Programmer
Software Developer (Senior)
Sweden Sweden
I have now moved to Sweden for love, and recently married a lovely Swede.

I started programming on BBC micros (6502) when I was six and never quite stopped even while I was supposed to be studying physics and uni.

I've been working for ~13 years writing software for machine control and data analysis. I now work on financial transaction transformation software, for a Software company in Gamlastan, Stockholm.
Look at my articles to see my excellent coding skills. I'm modest too!

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151002.1 | Last Updated 11 May 2004
Article Copyright 2004 by Iain Clarke, Warrior Programmer
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid