Click here to Skip to main content
15,892,697 members
Articles / Desktop Programming / MFC

How to wrap an MFC collection into an STL compliant iterator with the Boost iterator_facade

Rate me:
Please Sign up or sign in to vote.
4.56/5 (22 votes)
20 Oct 2008CPOL5 min read 55.9K   502   34  
How to wrap an MFC collection into an STL compliant iterator with the Boost iterator_facade.
// IterTestDoc.cpp : implementation of the CIterTestDoc class
//

#include "stdafx.h"
#include "IterTest.h"

#include "IterTestDoc.h"
#include "mfc_iters.h"
#include <string>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CIterTestDoc

IMPLEMENT_DYNCREATE(CIterTestDoc, CDocument)

BEGIN_MESSAGE_MAP(CIterTestDoc, CDocument)
   ON_COMMAND(ID_TESTMFCITERATORS_TESTCVIEWITERATOR, &CIterTestDoc::OnTestmfciteratorsTestcviewiterator)
END_MESSAGE_MAP()


// CIterTestDoc construction/destruction

CIterTestDoc::CIterTestDoc()
{
	// TODO: add one-time construction code here

}

CIterTestDoc::~CIterTestDoc()
{
}

BOOL CIterTestDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CIterTestDoc serialization

void CIterTestDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CIterTestDoc diagnostics

#ifdef _DEBUG
void CIterTestDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CIterTestDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CIterTestDoc commands

void CIterTestDoc::OnTestmfciteratorsTestcviewiterator()
{
   mfc_cview_iterator it = mfc_cview_iterator(this).begin();
   while(*it)
   {
      // Repaint the view
      std::string s = "Testing CView Iterator";
      it->SendMessage(MY_TEST_MSG, 0, (LPARAM)s.c_str());
      it++;
   }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Robotz Software
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions