Result Thus the calculator using command array was created successfully

Friday, May 28, 2010

OBJECTIVE:
To create a editor using multiple document interface this has the serializing ability to store the data as separate documents.
PROCEDURE:
1. Run the MFC App wizard (exe) to generate c:\mdi
2. Select multiple documents in step1 of App wizard.
3. Accept all the default settings.
4. In the step 6 of App wizard select CEditView as the base class.
5. Press OK to finish the wizard.
6. In the mdiDoc.cpp whether the serialize function has the following statement
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
This helps in storing data in the editor.
7. Using class wizard mao the WM_RBUUTONDOWN to CEditorViewID.
void CMDIView::OnRButtonDown(UINT nFlags, CPoint point)
{
char szTimestr[20];
CTime tm=CTime::GetCurrentTime();
sprintf(szTimestr,"its now %02d:%02d:%02d",tm.GetHour(),tm.GetMinute(),tm.GetSecond());
MessageBox(szTimestr,"is it time to quit yet",MB_OK);
CEditView::OnRButtonDown(nFlags, point);
}
8. The above coding will help to print the system date when the user presses the RBUTTONDOWN in each editor.
9. Compile and run the application.
10. The resultant editor will have all editing capabilities and loading capability.

PROGRAM:
SOURCE FILES:
mdiDoc.cpp :
// MDIDoc.cpp : implementation of the CMDIDoc class

 

#include "stdafx.h"
#include "MDI.h"
#include "MDIDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMDIDoc
IMPLEMENT_DYNCREATE(CMDIDoc, CDocument)
BEGIN_MESSAGE_MAP(CMDIDoc, CDocument)
//{{AFX_MSG_MAP(CMDIDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMDIDoc construction/destruction
CMDIDoc::CMDIDoc()
{
// TODO: add one-time construction code here
}
CMDIDoc::~CMDIDoc()
{
}
BOOL CMDIDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMDIDoc serialization
void CMDIDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*)m_viewList.GetHead())->SerializeRaw(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CMDIDoc diagnostics
#ifdef _DEBUG
void CMDIDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMDIDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMDIDoc commands


mdiview.cpp :
// MDIView.cpp : implementation of the CMDIView class
//
#include "stdafx.h"
#include "MDI.h"
#include "MDIDoc.h"
#include "MDIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMDIView
IMPLEMENT_DYNCREATE(CMDIView, CEditView)

BEGIN_MESSAGE_MAP(CMDIView, CEditView)
//{{AFX_MSG_MAP(CMDIView)
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CEditView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CEditView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMDIView construction/destruction
CMDIView::CMDIView()
{
// TODO: add construction code here
}
CMDIView::~CMDIView()
{
}
BOOL CMDIView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
BOOL bPreCreated = CEditView::PreCreateWindow(cs);
cs.style &= ~(ES_AUTOHSCROLLWS_HSCROLL); // Enable word-wrapping
return bPreCreated;
}
/////////////////////////////////////////////////////////////////////////////
// CMDIView drawing
void CMDIView::OnDraw(CDC* pDC)
{
CMDIDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMDIView printing
BOOL CMDIView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default CEditView preparation
return CEditView::OnPreparePrinting(pInfo);
}
void CMDIView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView begin printing.
CEditView::OnBeginPrinting(pDC, pInfo);
}
void CMDIView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// Default CEditView end printing
CEditView::OnEndPrinting(pDC, pInfo);
}
/////////////////////////////////////////////////////////////////////////////
// CMDIView diagnostics
#ifdef _DEBUG
void CMDIView::AssertValid() const
{
CEditView::AssertValid();
}
void CMDIView::Dump(CDumpContext& dc) const
{
CEditView::Dump(dc);
}
CMDIDoc* CMDIView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMDIDoc)));
return (CMDIDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMDIView message handlers
void CMDIView::OnRButtonDown(UINT nFlags, CPoint point)
{
char szTimestr[20];
CTime tm=CTime::GetCurrentTime();
sprintf(szTimestr,"its now %02d:%02d:%02d",tm.GetHour(),tm.GetMinute(),tm.GetSecond());
MessageBox(szTimestr,"is it time to quit yet",MB_OK);
CEditView::OnRButtonDown(nFlags, point);
}

HEADER FILES:
mdiDoc.h :
// MDIDoc.h : interface of the CMDIDoc class
#if !defined(AFX_MDIDOC_H__B63466B8_4323_4863_9EB5_879D95E1F1BB__INCLUDED_)
#define AFX_MDIDOC_H__B63466B8_4323_4863_9EB5_879D95E1F1BB__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMDIDoc : public CDocument
{
protected: // create from serialization only
CMDIDoc();
DECLARE_DYNCREATE(CMDIDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMDIDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMDIDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMDIDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};


0 comments:

Post a Comment