EastDrawDoc.cpp
上传用户:qiye66671
上传日期:2009-12-10
资源大小:182k
文件大小:15k
源码类别:

绘图程序

开发平台:

C/C++

  1. // EastDrawDoc.cpp : implementation of the CEastDrawDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "EastDraw.h"
  5. #include "EastDrawDoc.h"
  6. #include"EastDrawView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEastDrawDoc
  14. IMPLEMENT_DYNCREATE(CEastDrawDoc, CDocument)
  15. BEGIN_MESSAGE_MAP(CEastDrawDoc, CDocument)
  16. //{{AFX_MSG_MAP(CEastDrawDoc)
  17. ON_COMMAND(ID_FILE_SAVE_AS_Bmp, OnFILESAVEASBmp)
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CEastDrawDoc construction/destruction
  22. CEastDrawDoc::CEastDrawDoc()
  23. {
  24. // TODO: add one-time construction code here
  25. m_bChangeTitle=false;
  26. m_TotalSize=CSize(2000,2000);
  27. m_CenterPoint=CPoint(-1000,-1000);
  28. }
  29. CEastDrawDoc::~CEastDrawDoc()
  30. {
  31. }
  32. BOOL CEastDrawDoc::OnNewDocument()
  33. {
  34. if (!CDocument::OnNewDocument())
  35. return FALSE;
  36. // TODO: add reinitialization code here
  37. // (SDI documents will reuse this document)
  38.     
  39. return TRUE;
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CEastDrawDoc serialization
  43. void CEastDrawDoc::Serialize(CArchive& ar)
  44. {
  45. if (ar.IsStoring())
  46. {
  47.  ar<<m_TotalSize;
  48.  ar<<m_CenterPoint;
  49. // TODO: add storing code here
  50. }
  51. else
  52. {
  53. ar>>this->m_TotalSize;
  54. ar>>m_CenterPoint;
  55. // TODO: add loading code here
  56. }
  57. m_DLineArray.Serialize(ar);
  58. m_CurveArray.Serialize(ar);
  59. m_RectangleArray.Serialize(ar);
  60.     m_PolygonArray.Serialize(ar);
  61. m_RoundRectangleArray.Serialize(ar);
  62. m_RoundArray.Serialize(ar);
  63. m_EllipseArray.Serialize(ar);
  64.     m_LiEllipseArray.Serialize(ar);
  65. m_RoundArcArray.Serialize(ar);
  66. m_PolyBezierArray.Serialize(ar);
  67. m_TextArray.Serialize(ar);
  68. m_EllipseArcArray.Serialize(ar);
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CEastDrawDoc diagnostics
  72. #ifdef _DEBUG
  73. void CEastDrawDoc::AssertValid() const
  74. {
  75. CDocument::AssertValid();
  76. }
  77. void CEastDrawDoc::Dump(CDumpContext& dc) const
  78. {
  79. CDocument::Dump(dc);
  80. }
  81. #endif //_DEBUG
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CEastDrawDoc commands
  84. BOOL CEastDrawDoc::SaveBitMap(CFile&file)
  85. {
  86. CEastDrawView*pView;
  87. POSITION pos=GetFirstViewPosition();
  88. pView=(CEastDrawView*)GetNextView(pos);
  89.     return pView->SaveDIB(NULL,file);
  90. }
  91. void CEastDrawDoc::AddTempFile()
  92. {
  93.     m_bChangeTitle=true;
  94. HANDLE hFind;
  95. WIN32_FIND_DATA dataFind;
  96. BOOL bMoreFiles=TRUE;
  97. CString strTitle;
  98.     strTitle=GetTitle();
  99.     char    tmpPathc[_MAX_PATH+1];
  100.     GetTempPath(_MAX_PATH,tmpPathc);
  101. CString tmpPath=tmpPathc;
  102. hFind=FindFirstFile(tmpPath+"\EdTemp",&dataFind);
  103.    
  104. if(hFind==INVALID_HANDLE_VALUE)
  105. {
  106.     FindClose(hFind);
  107.         ::CreateDirectory(tmpPath+"\EdTemp",NULL);
  108. ::CreateDirectory(tmpPath+"\EdTemp\"+strTitle,NULL);
  109.   
  110. }
  111. else
  112. {   
  113. FindClose(hFind);
  114.         hFind=FindFirstFile(tmpPath+"\EdTemp\"+strTitle,&dataFind);
  115.         if(hFind==INVALID_HANDLE_VALUE)
  116. {
  117. ::CreateDirectory(tmpPath+"\EdTemp\"+strTitle,NULL);
  118. }
  119. }
  120.       CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
  121. file1.Close();
  122. CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
  123. file2.Close();
  124. CFile file3(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
  125.     file3.Close();
  126. CFile file4(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  127.     file4.Close();
  128. CFile file5(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  129.     file5.Close();
  130. CFile file6(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  131.     file6.Close();
  132. FindClose(hFind);
  133.    
  134. }
  135. void CEastDrawDoc::AutoSave()
  136. {
  137.    
  138. CString strTitle;
  139.     strTitle=GetTitle();
  140.     char    tmpPathc[_MAX_PATH+1];
  141.     GetTempPath(_MAX_PATH,tmpPathc);
  142. CString tmpPath=tmpPathc;
  143.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
  144. CArchive ar(&file1,CArchive::store);
  145.     Serialize(ar);
  146.     //file1.Close();
  147. CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
  148. CArchive ar2(&file2,CArchive::store);
  149.     Serialize(ar2);
  150.    /// file2.Close();
  151. CFile file3(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
  152. CArchive ar3(&file3,CArchive::store);
  153.     Serialize(ar3);
  154.     CFile file4(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  155. CArchive ar4(&file4,CArchive::store);
  156.     Serialize(ar4);
  157. CFile file5(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  158. CArchive ar5(&file5,CArchive::store);
  159.     Serialize(ar5);
  160.     
  161. CFile file6(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  162. CArchive ar6(&file6,CArchive::store);
  163.     Serialize(ar6);
  164.   //file3.Close();
  165. }
  166. BOOL CEastDrawDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  167. {
  168. if (!CDocument::OnOpenDocument(lpszPathName))
  169. return FALSE;
  170. // TODO: Add your specialized creation code here
  171. return TRUE;
  172. }
  173. void CEastDrawDoc::ExchangeSave(int index,int&rtimes)
  174. {
  175. //Requeue(index,rtimes);
  176. CString strTitle;
  177.     strTitle=GetTitle();
  178.     char    tmpPathc[_MAX_PATH+1];
  179.     GetTempPath(_MAX_PATH,tmpPathc);
  180. CString tmpPath=tmpPathc;
  181.   
  182. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed")); 
  183. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"));
  184. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"));
  185.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  186.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  187. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  188.    
  189.    
  190. CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"),CFile::modeReadWrite|CFile::modeCreate);
  191. CArchive ar(&file1,CArchive::store);
  192.     Serialize(ar);
  193.    //OPENFILENAME ofn;  // older version
  194.    //memset(&ofn, 0, sizeof(ofn));
  195.    //ofn.lStructSize = sizeof(ofn);
  196.    //int nResult = ::GetOpenFileName(&ofn);
  197. }
  198. void CEastDrawDoc::OnBUTTON32858OnDo(int index)
  199. {
  200.     CString strTitle;
  201.     strTitle=GetTitle();
  202.     char    tmpPathc[_MAX_PATH+1];
  203.     GetTempPath(_MAX_PATH,tmpPathc);
  204. CString tmpPath=tmpPathc;
  205. // CString str;
  206. // str.Format("%d",index);
  207.  //AfxMessageBox(str);
  208.   if(index==0)
  209. {
  210.         CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  211.     CArchive ar(&file1,CArchive::load);
  212.         Serialize(ar); 
  213. }
  214.  if(index==1)
  215.  {
  216.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  217.     CArchive ar(&file1,CArchive::load);
  218.         Serialize(ar); 
  219.  }  
  220.         
  221.  if(index==2)
  222.  {
  223.         CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  224.     CArchive ar(&file1,CArchive::load);
  225.         Serialize(ar); 
  226.  }
  227.  if(index==3)
  228.  {
  229.       CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  230.   CArchive ar(&file1,CArchive::load);
  231.       Serialize(ar); 
  232. }
  233. if(index==4)
  234.  {
  235.       CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  236.   CArchive ar(&file1,CArchive::load);
  237.       Serialize(ar); 
  238. if(index==5)
  239.  {
  240.       CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate);
  241.   CArchive ar(&file1,CArchive::load);
  242.       Serialize(ar); 
  243. }
  244. void CEastDrawDoc::OnFILESAVEASBmp() 
  245. {
  246. // TODO: Add your command handler code here
  247.  
  248.   TCHAR szFilters[]=_T("BMP 文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||");
  249.  
  250.   CFileDialog dlg(false,_T("bmp"),_T("*.bmp"),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilters);
  251.   if(dlg.DoModal()==IDOK)
  252.  {
  253.  
  254.   CFile file;
  255.   CFileException fe;
  256.   
  257.    if (!file.Open(dlg.GetPathName(), CFile::modeCreate |
  258.     CFile::modeWrite ,&fe))
  259.   {
  260.  
  261.       fe.ReportError();
  262.   fe.Delete();
  263.   return  ;
  264.   }
  265.    
  266.  
  267.   BOOL bSuccess = FALSE;
  268.   TRY
  269.   {
  270.   BeginWaitCursor();
  271.   bSuccess = SaveBitMap(file);
  272.   file.Close();
  273.   }
  274.   CATCH (CException, eSave)
  275.   {
  276.   file.Abort();
  277.   EndWaitCursor();
  278.  
  279.   eSave->ReportError();
  280.   eSave->Delete();
  281.   return ;
  282.   }
  283.   END_CATCH
  284.  
  285.   EndWaitCursor();
  286.     
  287.  if (!bSuccess)
  288.   {
  289.  
  290.   CString strMsg;
  291.   strMsg.Format("保存失败,请稍后重试");
  292.   AfxMessageBox(strMsg);
  293.   }
  294.  
  295.  }
  296. }
  297. void CEastDrawDoc::ReMoveTemp()
  298. {   
  299. CString strTitle;
  300.     strTitle=GetTitle();
  301.     char    tmpPathc[_MAX_PATH+1];
  302.     GetTempPath(_MAX_PATH,tmpPathc);
  303. CString tmpPath=tmpPathc;
  304.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"));
  305.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"));
  306.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  307.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  308. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  309. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  310.     
  311. ::RemoveDirectory(_T(tmpPath+"\EdTemp\"+strTitle));
  312.     ::RemoveDirectory(_T(tmpPath+"\EdTemp\"));
  313. }
  314. void CEastDrawDoc::Requeue(int &index, int &rtimes)
  315. {
  316. CString strTitle;
  317.     strTitle=GetTitle();
  318.     char    tmpPathc[_MAX_PATH+1];
  319.     GetTempPath(_MAX_PATH,tmpPathc);
  320. CString tmpPath=tmpPathc;
  321.    if(index==0)
  322.    {
  323.     rtimes=rtimes<6?rtimes:6;
  324.    }
  325.    if(index==1)
  326.    {
  327.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed")); 
  328. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  329. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  330.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  331.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  332. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"));
  333.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  334.     rtimes=rtimes<5?rtimes:5;
  335.    }
  336.    if(index==2)
  337.    {
  338.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  339. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  340.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  341.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  342.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  343. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  344.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  345.     CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  346.     rtimes=rtimes<4?rtimes:4;
  347.    }
  348.    if(index==3)
  349.    {
  350.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  351. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  352.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  353.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  354.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  355. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  356.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  357.     CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  358.     CFile file3(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  359.     rtimes=rtimes<3?rtimes:3;
  360.    }
  361.    if(index==4)
  362.    {
  363.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  364. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  365.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  366.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  367.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  368. CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  369.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  370.     CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  371.     CFile file3(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  372.      CFile file4(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
  373.  rtimes=rtimes<2?rtimes:2;
  374.    }
  375.  if(index==5)
  376.    {
  377.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  378. CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"));
  379.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"));
  380.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"));
  381.     CFile::Remove(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"));
  382.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),_T(tmpPath+"\EdTemp\"+strTitle+"\First.ed"));
  383.     CFile file1(_T(tmpPath+"\EdTemp\"+strTitle+"\Six.ed"),CFile::modeReadWrite|CFile::modeCreate);
  384.     CFile file2(_T(tmpPath+"\EdTemp\"+strTitle+"\Fifth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  385.     CFile file3(_T(tmpPath+"\EdTemp\"+strTitle+"\Forth.ed"),CFile::modeReadWrite|CFile::modeCreate);
  386.     CFile file4(_T(tmpPath+"\EdTemp\"+strTitle+"\Third.ed"),CFile::modeReadWrite|CFile::modeCreate);
  387.     CFile file5(_T(tmpPath+"\EdTemp\"+strTitle+"\Second.ed"),CFile::modeReadWrite|CFile::modeCreate);
  388.     rtimes=rtimes<1?rtimes:1;
  389.  }
  390. }
  391. void CEastDrawDoc::SetTitle(LPCTSTR lpszTitle) 
  392. {
  393. // TODO: Add your specialized code here and/or call the base class
  394.   
  395.    if(m_bChangeTitle)
  396. {
  397. CString strTitle;
  398.     strTitle=GetTitle();
  399.     char    tmpPathc[_MAX_PATH+1];
  400.     GetTempPath(_MAX_PATH,tmpPathc);
  401. CString tmpPath=tmpPathc;
  402.     CFile::Rename(_T(tmpPath+"\EdTemp\"+strTitle),_T(tmpPath+"\EdTemp\"+lpszTitle));
  403.     }
  404. CDocument::SetTitle(lpszTitle);
  405. }