123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- // EastDrawDoc.cpp : implementation of the CEastDrawDoc class
- //
- #include "stdafx.h"
- #include "EastDraw.h"
- #include "EastDrawDoc.h"
- #include"EastDrawView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEastDrawDoc
- IMPLEMENT_DYNCREATE(CEastDrawDoc, CDocument)
- BEGIN_MESSAGE_MAP(CEastDrawDoc, CDocument)
- //{{AFX_MSG_MAP(CEastDrawDoc)
- ON_COMMAND(ID_FILE_SAVE_AS_Bmp, OnFILESAVEASBmp)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEastDrawDoc construction/destruction
- CEastDrawDoc::CEastDrawDoc()
- {
- // TODO: add one-time construction code here
- m_bChangeTitle=false;
- m_TotalSize=CSize(2000,2000);
- m_CenterPoint=CPoint(-1000,-1000);
- }
- CEastDrawDoc::~CEastDrawDoc()
- {
- }
- BOOL CEastDrawDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
-
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEastDrawDoc serialization
- void CEastDrawDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- ar<<m_TotalSize;
- ar<<m_CenterPoint;
- // TODO: add storing code here
- }
- else
- {
- ar>>this->m_TotalSize;
- ar>>m_CenterPoint;
- // TODO: add loading code here
- }
- m_DLineArray.Serialize(ar);
- m_CurveArray.Serialize(ar);
- m_RectangleArray.Serialize(ar);
- m_PolygonArray.Serialize(ar);
- m_RoundRectangleArray.Serialize(ar);
- m_RoundArray.Serialize(ar);
- m_EllipseArray.Serialize(ar);
- m_LiEllipseArray.Serialize(ar);
- m_RoundArcArray.Serialize(ar);
- m_PolyBezierArray.Serialize(ar);
- m_TextArray.Serialize(ar);
- m_EllipseArcArray.Serialize(ar);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEastDrawDoc diagnostics
- #ifdef _DEBUG
- void CEastDrawDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CEastDrawDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEastDrawDoc commands
- BOOL CEastDrawDoc::SaveBitMap(CFile&file)
- {
- CEastDrawView*pView;
- POSITION pos=GetFirstViewPosition();
- pView=(CEastDrawView*)GetNextView(pos);
- return pView->SaveDIB(NULL,file);
- }
- void CEastDrawDoc::AddTempFile()
- {
- m_bChangeTitle=true;
- HANDLE hFind;
- WIN32_FIND_DATA dataFind;
- BOOL bMoreFiles=TRUE;
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
- hFind=FindFirstFile(tmpPath+"\\EdTemp",&dataFind);
-
- if(hFind==INVALID_HANDLE_VALUE)
- {
- FindClose(hFind);
- ::CreateDirectory(tmpPath+"\\EdTemp",NULL);
- ::CreateDirectory(tmpPath+"\\EdTemp\\"+strTitle,NULL);
-
- }
- else
- {
- FindClose(hFind);
- hFind=FindFirstFile(tmpPath+"\\EdTemp\\"+strTitle,&dataFind);
- if(hFind==INVALID_HANDLE_VALUE)
- {
- ::CreateDirectory(tmpPath+"\\EdTemp\\"+strTitle,NULL);
- }
- }
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file1.Close();
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file2.Close();
- CFile file3(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file3.Close();
- CFile file4(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file4.Close();
- CFile file5(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file5.Close();
- CFile file6(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- file6.Close();
- FindClose(hFind);
-
- }
- void CEastDrawDoc::AutoSave()
- {
-
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar(&file1,CArchive::store);
- Serialize(ar);
- //file1.Close();
-
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar2(&file2,CArchive::store);
- Serialize(ar2);
- /// file2.Close();
-
- CFile file3(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar3(&file3,CArchive::store);
- Serialize(ar3);
- CFile file4(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar4(&file4,CArchive::store);
- Serialize(ar4);
- CFile file5(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar5(&file5,CArchive::store);
- Serialize(ar5);
-
- CFile file6(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar6(&file6,CArchive::store);
- Serialize(ar6);
- //file3.Close();
- }
- BOOL CEastDrawDoc::OnOpenDocument(LPCTSTR lpszPathName)
- {
- if (!CDocument::OnOpenDocument(lpszPathName))
- return FALSE;
-
- // TODO: Add your specialized creation code here
-
- return TRUE;
- }
- void CEastDrawDoc::ExchangeSave(int index,int&rtimes)
- {
- //Requeue(index,rtimes);
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
-
-
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
-
-
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CArchive ar(&file1,CArchive::store);
- Serialize(ar);
- //OPENFILENAME ofn; // older version
- //memset(&ofn, 0, sizeof(ofn));
- //ofn.lStructSize = sizeof(ofn);
- //int nResult = ::GetOpenFileName(&ofn);
- }
- void CEastDrawDoc::OnBUTTON32858OnDo(int index)
- {
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
- // CString str;
- // str.Format("%d",index);
- //AfxMessageBox(str);
- if(index==0)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
-
- if(index==1)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
-
- if(index==2)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
- if(index==3)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
- if(index==4)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
- if(index==5)
- {
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
- CArchive ar(&file1,CArchive::load);
- Serialize(ar);
- }
- }
- void CEastDrawDoc::OnFILESAVEASBmp()
- {
- // TODO: Add your command handler code here
-
- TCHAR szFilters[]=_T("BMP 文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
-
- CFileDialog dlg(false,_T("bmp"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
- if(dlg.DoModal()==IDOK)
- {
-
- CFile file;
- CFileException fe;
-
- if (!file.Open(dlg.GetPathName(), CFile::modeCreate |
- CFile::modeWrite ,&fe))
- {
-
- fe.ReportError();
- fe.Delete();
- return ;
- }
-
-
- BOOL bSuccess = FALSE;
- TRY
- {
- BeginWaitCursor();
- bSuccess = SaveBitMap(file);
- file.Close();
- }
- CATCH (CException, eSave)
- {
- file.Abort();
- EndWaitCursor();
-
- eSave->ReportError();
- eSave->Delete();
- return ;
- }
- END_CATCH
-
- EndWaitCursor();
-
- if (!bSuccess)
- {
-
- CString strMsg;
- strMsg.Format("保存失败,请稍后重试");
- AfxMessageBox(strMsg);
- }
-
- }
- }
- void CEastDrawDoc::ReMoveTemp()
- {
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
-
- ::RemoveDirectory(_T(tmpPath+"\\EdTemp\\"+strTitle));
- ::RemoveDirectory(_T(tmpPath+"\\EdTemp\\"));
- }
- void CEastDrawDoc::Requeue(int &index, int &rtimes)
- {
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
- if(index==0)
- {
- rtimes=rtimes<6?rtimes:6;
- }
- if(index==1)
- {
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"));
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- rtimes=rtimes<5?rtimes:5;
- }
- if(index==2)
- {
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- rtimes=rtimes<4?rtimes:4;
- }
- if(index==3)
- {
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file3(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- rtimes=rtimes<3?rtimes:3;
- }
- if(index==4)
- {
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file3(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file4(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
- rtimes=rtimes<2?rtimes:2;
- }
- if(index==5)
- {
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"));
- CFile::Remove(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"));
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),_T(tmpPath+"\\EdTemp\\"+strTitle+"\\First.ed"));
- CFile file1(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file2(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file3(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file4(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
- CFile file5(_T(tmpPath+"\\EdTemp\\"+strTitle+"\\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
- rtimes=rtimes<1?rtimes:1;
- }
- }
- void CEastDrawDoc::SetTitle(LPCTSTR lpszTitle)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- if(m_bChangeTitle)
- {
- CString strTitle;
- strTitle=GetTitle();
- char tmpPathc[_MAX_PATH+1];
- GetTempPath(_MAX_PATH,tmpPathc);
- CString tmpPath=tmpPathc;
-
- CFile::Rename(_T(tmpPath+"\\EdTemp\\"+strTitle),_T(tmpPath+"\\EdTemp\\"+lpszTitle));
- }
-
- CDocument::SetTitle(lpszTitle);
-
- }
|