Click here to Skip to main content
12,896,953 members (53,716 online)
Click here to Skip to main content


550 bookmarked
Posted 5 Dec 2006

Neural Network for Recognition of Handwritten Digits

, 5 Dec 2006
A convolutional neural network achieves 99.26% accuracy on a modified NIST database of hand-written digits.
// CntrItem.cpp : implementation of the CMNistCntrItem class

#include "stdafx.h"
#include "MNist.h"

#include "MNistDoc.h"
#include "MNistView.h"
#include "CntrItem.h"

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

// CMNistCntrItem implementation

IMPLEMENT_SERIAL(CMNistCntrItem, COleClientItem, 0)

CMNistCntrItem::CMNistCntrItem(CMNistDoc* pContainer)
	: COleClientItem(pContainer)
	// TODO: add one-time construction code here

	// TODO: add cleanup code here

void CMNistCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)

	COleClientItem::OnChange(nCode, dwParam);

	// When an item is being edited (either in-place or fully open)
	//  it sends OnChange notifications for changes in the state of the
	//  item or visual appearance of its content.

	// TODO: invalidate the item by calling UpdateAllViews
	//  (with hints appropriate to your application)

		// for now just update ALL views/no hints

BOOL CMNistCntrItem::OnChangeItemPosition(const CRect& rectPos)

	// During in-place activation CMNistCntrItem::OnChangeItemPosition
	//  is called by the server to change the position of the in-place
	//  window.  Usually, this is a result of the data in the server
	//  document changing such that the extent has changed or as a result
	//  of in-place resizing.
	// The default here is to call the base class, which will call
	//  COleClientItem::SetItemRects to move the item
	//  to the new position.

	if (!COleClientItem::OnChangeItemPosition(rectPos))
		return FALSE;

	// TODO: update any cache you may have of the item's rectangle/extent

	return TRUE;

void CMNistCntrItem::OnGetItemPosition(CRect& rPosition)

	// During in-place activation, CMNistCntrItem::OnGetItemPosition
	//  will be called to determine the location of this item.  The default
	//  implementation created from AppWizard simply returns a hard-coded
	//  rectangle.  Usually, this rectangle would reflect the current
	//  position of the item relative to the view used for activation.
	//  You can obtain the view by calling CMNistCntrItem::GetActiveView.

	// TODO: return correct rectangle (in pixels) in rPosition

	rPosition.SetRect(10, 10, 210, 210);

void CMNistCntrItem::OnActivate()
    // Allow only one inplace activate item per frame
    CMNistView* pView = GetActiveView();
    COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
    if (pItem != NULL && pItem != this)

void CMNistCntrItem::OnDeactivateUI(BOOL bUndoable)

    // Hide the object if it is not an outside-in object
    DWORD dwMisc = 0;
    m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
    if (dwMisc & OLEMISC_INSIDEOUT)
        DoVerb(OLEIVERB_HIDE, NULL);

void CMNistCntrItem::Serialize(CArchive& ar)

	// Call base class first to read in COleClientItem data.
	// Since this sets up the m_pDocument pointer returned from
	//  CMNistCntrItem::GetDocument, it is a good idea to call
	//  the base class Serialize first.

	// now store/retrieve data specific to CMNistCntrItem
	if (ar.IsStoring())
		// TODO: add storing code here
		// TODO: add loading code here

// CMNistCntrItem diagnostics

#ifdef _DEBUG
void CMNistCntrItem::AssertValid() const

void CMNistCntrItem::Dump(CDumpContext& dc) const


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

Mike O'Neill
United States United States
Mike O'Neill is a patent attorney in Southern California, where he specializes in computer and software-related patents. He programs as a hobby, and in a vain attempt to keep up with and understand the technology of his clients.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 5 Dec 2006
Article Copyright 2006 by Mike O'Neill
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid