📄 myobjcommand.cpp
字号:
// MyObjCommand.cpp: implementation of the CMyObjCommand class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TestUndo.h"
#include "MyObjCommand.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMyObjCommand::CMyObjCommand(CTestUndoDoc * pDoc, int nOperID,CMyObject * pObj,CRect rect)
{
m_pDoc = pDoc;
m_nOperID = nOperID;
m_rect = rect;
m_pObj = pObj;
ASSERT(m_pDoc);
}
CMyObjCommand::~CMyObjCommand()
{
if( m_nOperID == 0 )
{
m_pObj->Release( );
}
}
bool CMyObjCommand::Execute( )
{
if( m_nOperID == 0 ) // 增加对象
{
m_pObj = new CMyObject( m_rect );
m_pObj->AddRef( );
m_pDoc->m_objects.Add( m_pObj );
}
else if( m_nOperID == 1 ) // 更改属性
{
ASSERT(m_pObj);
CRect rect = m_pObj->GetObjRect();
m_pObj->SetObjRect( m_rect );
m_rect = rect;
}
return true;
}
bool CMyObjCommand::Unexecute( )
{
if( m_nOperID == 0 )
{
m_pDoc->m_objects.Remove( m_pObj );
}
else if( m_nOperID == 1 )
{
ASSERT(m_pObj);
CRect rect = m_pObj->GetObjRect();
m_pObj->SetObjRect(m_rect);
m_rect = rect;
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -