www.pudn.com > MyDraw1225.rar > MyDrawDoc.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; 
}