⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mydrawdoc.cpp

📁 此源程序是一个简单的绘图程序,你通过他可以画一些简单的图形,是一款简单的画图程序,你通过他可是学到VC的图形编程.
💻 CPP
字号:
// MyDrawDoc.cpp : implementation of the CMyDrawDoc class
//

#include "stdafx.h"
#include "MyDraw.h"

#include "MyDrawDoc.h"
#include "MyDrawView.h"
#include "LineProperties.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc

IMPLEMENT_DYNCREATE(CMyDrawDoc, CDocument)

BEGIN_MESSAGE_MAP(CMyDrawDoc, CDocument)
//{{AFX_MSG_MAP(CMyDrawDoc)
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc construction/destruction

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

CMyDrawDoc::~CMyDrawDoc()
{
}

BOOL CMyDrawDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;
	
	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	POSITION viewPos=this->GetFirstViewPosition();
	CMyDrawView * MyView=(CMyDrawView *)this->GetNextView(viewPos);
	MyView->m_ObjectList.RemoveAll();  
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc serialization

void CMyDrawDoc::Serialize(CArchive& ar)
{
	POSITION pos;
	if (ar.IsStoring())
	{
		// TODO: add storing code here
		POSITION viewPos=this->GetFirstViewPosition();
		CMyDrawView * MyView=(CMyDrawView *)this->GetNextView(viewPos);
		pos = MyView->m_ObjectList.GetHeadPosition();
		while(pos != NULL)
		{
			ar << (CObject*)(MyView->m_ObjectList.GetNext(pos));
		}
	}
	else
	{
		// TODO: add loading code here
		POSITION viewPos=this->GetFirstViewPosition();
		CMyDrawView * MyView=(CMyDrawView *)this->GetNextView(viewPos);
		MyView->m_ObjectList.RemoveAll();  

		CObject * pObject;
		do{
			try
			{
				ar >> pObject;
				MyView->m_ObjectList.AddTail(pObject);
			}
			catch(CException * e)
			{
				e->Delete();
				break;
			}
		}while(pObject != NULL);
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc commands

BOOL CMyDrawDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// TODO: Add your specialized creation code here
    OFSTRUCT of;
    HANDLE hFile = NULL;;
	hFile=(HANDLE)OpenFile(lpszPathName,&of,OF_READ|OF_SHARE_COMPAT);
	if (hFile!=(HANDLE)HFILE_ERROR)
	{
		DWORD dwHighWord = NULL;
		DWORD dwSizeLow = GetFileSize(hFile,&dwHighWord );
		DWORD dwFileSize = dwSizeLow;
		if(0==dwFileSize)
		{
			POSITION viewPos=this->GetFirstViewPosition();
			CMyDrawView * MyView=(CMyDrawView *)this->GetNextView(viewPos);
			MyView->m_ObjectList.RemoveAll();  
		}
	}
	return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -