【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“imageCAMDoc.cpp”一文,供大家参考学习
// imageCAMDoc.cpp : implementation of the CimageCAMDoc class
//
#include "stdafx.h"
#include "imageCAM.h"
#include "windowsx.h"
#include "imageCAMDoc.h"
#include "imageCAMView.h"
#include "dib.h"
#include "PreviewFileDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////added by ljh:start////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//说明:对不同的视图执行undo/redo功能的记数
int RunTimes=0; //记录不同视图的undo临时文件标记
extern CString setszCurDir;
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////added by ljh:end////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CimageCAMDoc
IMPLEMENT_DYNCREATE(CimageCAMDoc, CDocument)
BEGIN_MESSAGE_MAP(CimageCAMDoc, CDocument)
//{{AFX_MSG_MAP(CimageCAMDoc)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CimageCAMDoc, CDocument)
//{{AFX_DISPATCH_MAP(CimageCAMDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IimageCAM to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {57ECEFC5-C909-11D2-83AE-5254AB1C48FD}
static const IID IID_IimageCAM =
{ 0x57ecefc5, 0xc909, 0x11d2, { 0x83, 0xae, 0x52, 0x54, 0xab, 0x1c, 0x48, 0xfd } };
BEGIN_INTERFACE_MAP(CimageCAMDoc, CDocument)
INTERFACE_PART(CimageCAMDoc, IID_IimageCAM, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CimageCAMDoc construction/destruction
CimageCAMDoc::CimageCAMDoc()
{
// TODO: add one-time construction code here
m_pDib = new CDib;
m_pDib->Create(DEFAULT_HEIGHT, DEFAULT_WIDTH,24);
CPoint x(0,0);CPoint y(DEFAULT_HEIGHT, DEFAULT_WIDTH);
CRect rc(x,y);
m_pDib->CutRect(rc);
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////added by ljh:start////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
//说明:执行undo/redo功能
if(!SetCuurentDirectory())
{
CString str="undo/redo功能无法实现!\n请不要使用这两项功能!!";
AfxMessageBox(str);//,"warning");
}
fileindex=0; //记录某个undo的临时文件组索引fileindex,fileindex+1为下一步要记录的文件(isrecover)为false;
//或者是要恢复的文件;isrecover)为true时;
CreatTmpFile();
RunTimes++;
isundodone=FALSE;
//tfilestr[0]=NULL;
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////added by ljh:end////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
EnableAutomation();
AfxOleLockApp();
}
CimageCAMDoc::~CimageCAMDoc()
{
AfxOleUnlockApp();
if (m_pDib != NULL)
delete m_pDib;
if(SetCuurentDirectory())
{
for(int index=0;index<4;index++)
{
if (tfilestr[index].Fundo!=NULL)
{
tfilestr[index].Fundo.Remove(tfilestr[index].FileName);
}
}
}
}
BOOL CimageCAMDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CimageCAMDoc serialization
void CimageCAMDoc::Serialize(CArchive& ar)
{
m_pDib->Serialize(ar);
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CimageCAMDoc diagnostics
#ifdef _DEBUG
void CimageCAMDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CimageCAMDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CimageCAMDoc commands
void CimageCAMDoc::CreatTmpFile() //功能:创建临时文件的函数
//参数:int i 为传递的文件的索引值fileindex;
{
for(int j=0;j<4;j++)
{
char p1[4];
sprintf(p1,"%d%d",RunTimes,j);
tfilestr[j].FileName="tempdraw";
tfilestr[j].FileName+=p1;
tfilestr[j].FileName+=".tmp";
//tfilestr[j].Fundo.Open(tfilestr[j].FileName,CFile::modeCreate|CFile::modeReadWrite|CFile::typeBinary);
CFileException e;
// char* pFileName = "test.dat";
if( !tfilestr[j].Fundo.Open(tfilestr[j].FileName,CFile::modeCreate|CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
AfxMessageBox("创建临时文件出错,请慎用图象菜单");
#endif
return;
}
DWORD dwFileAttributes=::GetFileAttributes(tfilestr[j].FileName);
dwFileAttributes|=FILE_ATTRIBUTE_HIDDEN;
::SetFileAttributes(tfilestr[j].FileName,dwFileAttributes);
tfilestr[j].Fundo.Close();
tfilestr[j].isfilerecover=FALSE;
}
}
void CimageCAMDoc::EditUndo()
{
// TODO: Add your command handle
// if(!tfilestr[fileindex%4].isfilerecover)
// {
WriteFile();
tfilestr[fileindex%4].isfilerecover=TRUE;
// }
fileindex=fileindex-1;//将文件索引后移一位:要读入文件dib值
if(ReadFile())
{
m_pDib->UpdateInternal();
SetModifiedFlag(TRUE);
}
}
void CimageCAMDoc::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if((fileindex>=1)&&tfilestr[(fileindex-1)%4].isfilerecover==FALSE)
pCmdUI->Enable(TRUE);
else
pCmdUI->Enable(FALSE);
}
BOOL CimageCAMDoc::ReadTmpFile()
{ if(!SetCuurentDirectory())
上一篇:
imageCAM.cpp
下一篇:
那些令你为之触动的好句子,感慨万分