// enable CObject-derived classes to be created dynamically at run time
IMPLEMENT_DYNCREATE(View1, CView)
IMPLEMENT_DYNCREATE(View, CView)
IMPLEMENT_DYNCREATE(Doc, CDocument)
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
//message map for the application window
BEGIN_MESSAGE_MAP(App, CWinApp)
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
ON_COMMAND(IDR_VIEW1, SwapView1)
ON_COMMAND(IDR_VIEW2, SwapView2)
END_MESSAGE_MAP()
//message map for the frame window
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
//message map for the document window
BEGIN_MESSAGE_MAP(Doc, CDocument)
END_MESSAGE_MAP()
//message map for the first view window
BEGIN_MESSAGE_MAP(View, CView)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
//message map for the second view window
BEGIN_MESSAGE_MAP(View1, CView)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
App theApp;//instantiate the application
// Application initialization
BOOL App::InitInstance()
{ //Enable and load the list of most recently used (MRU) files
LoadStdProfileSettings(); //defines a document template that implements the single document interface
CSingleDocTemplate* pDocTemplate;
pDocTemplate =new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(Doc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(View));
AddDocTemplate(pDocTemplate); // Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow(); return TRUE;
}
//sets array to position of click
Doc::SetNewValue(int x,int y)
{
clickcount=clickcount+1; if (clickcount<10)
{
px[clickcount]=x;
py[clickcount]=y;
}
}
//deals with loading or saving the document void Doc::Serialize(CArchive& ar)
{ //used for saving document data if (ar.IsStoring())
{
ar<< clickcount; for (int i=1;i<=clickcount;i++)
{
ar<<px[i];
ar<<py[i];
}
} //loading document data else
{
ar >> clickcount; for (int i=1;i<=clickcount;i++)
{
ar>>px[i];
ar>>py[i];
}
}
}
//draws to first view void View::OnDraw(CDC* pDC)
{
Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc); int x=0,y=0; int totalclicks=pDoc->clickcount; for (int i=1;i<=totalclicks;i++)
{
x=pDoc->px[i];
y=pDoc->py[i];
pDC->TextOut(x, y, "x", 1);
}
}
//deals with left buttons click in first view void View::OnLButtonDown(UINT nFlags, CPoint point )
{
Doc* pDoc = GetDocument();
pDoc->SetNewValue(point.x,point.y);
pDoc->UpdateAllViews(NULL);
}
//draws to second view void View1::OnDraw(CDC* pDC)
{
Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc); int x=0,y=0; int totalclicks=pDoc->clickcount; for (int i=1;i<=totalclicks;i++)
{
x=pDoc->px[i];
y=pDoc->py[i];
pDC->TextOut(x, y, "*", 1);
}
} //deals with left buttons click in second view void View1::OnLButtonDown(UINT nFlags, CPoint point )
{
Doc* pDoc = GetDocument();
pDoc->SetNewValue(point.x,point.y);
pDoc->UpdateAllViews(NULL);
}