📄 lq01doc.cpp
字号:
// lq01Doc.cpp : implementation of the CLq01Doc class
//
#include "stdafx.h"
#include "lq01.h"
#include "lq01Doc.h"
#include "line.h"
#include "shape.h"
#include "myrect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLq01Doc
IMPLEMENT_DYNCREATE(CLq01Doc, CDocument)
BEGIN_MESSAGE_MAP(CLq01Doc, CDocument)
//{{AFX_MSG_MAP(CLq01Doc)
ON_COMMAND(ID_COLOR_BLACK, OnColorBlack)
ON_UPDATE_COMMAND_UI(ID_COLOR_BLACK, OnUpdateColorBlack)
ON_COMMAND(ID_COLOR_BLUE, OnColorBlue)
ON_UPDATE_COMMAND_UI(ID_COLOR_BLUE, OnUpdateColorBlue)
ON_COMMAND(ID_COLOR_CYAN, OnColorCyan)
ON_UPDATE_COMMAND_UI(ID_COLOR_CYAN, OnUpdateColorCyan)
ON_COMMAND(ID_COLOR_GREEN, OnColorGreen)
ON_UPDATE_COMMAND_UI(ID_COLOR_GREEN, OnUpdateColorGreen)
ON_COMMAND(ID_COLOR_RED, OnColorRed)
ON_UPDATE_COMMAND_UI(ID_COLOR_RED, OnUpdateColorRed)
ON_COMMAND(ID_COLOR_MAGENTA, OnColorMagenta)
ON_UPDATE_COMMAND_UI(ID_COLOR_MAGENTA, OnUpdateColorMagenta)
ON_COMMAND(ID_COLOR_WHITE, OnColorWhite)
ON_UPDATE_COMMAND_UI(ID_COLOR_WHITE, OnUpdateColorWhite)
ON_COMMAND(ID_COLOR_YELLOW, OnColorYellow)
ON_UPDATE_COMMAND_UI(ID_COLOR_YELLOW, OnUpdateColorYellow)
ON_COMMAND(ID_SHAPE_LINE, OnShapeLine)
ON_UPDATE_COMMAND_UI(ID_SHAPE_LINE, OnUpdateShapeLine)
ON_COMMAND(ID_SHAPE_RECTANGLE, OnShapeRectangle)
ON_UPDATE_COMMAND_UI(ID_SHAPE_RECTANGLE, OnUpdateShapeRectangle)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
const COLORREF CLq01Doc::m_crColors [8]={
RGB(0,0,0),
RGB(0,0,255),
RGB(0,255,0),
RGB(0,255,255),
RGB(255,0,0),
RGB(255,0,255),
RGB(255,255,0),
RGB(255,255,255)
};
/////////////////////////////////////////////////////////////////////////////
// CLq01Doc construction/destruction
CLq01Doc::CLq01Doc()
{
// TODO: add one-time construction code here
/*
if(m_nShape==0)
{ m_MyShape=&m_MyLine;
m_MyShape_t=&m_MyLine_t;
}
else
{ m_MyShape=&m_MyRect;
m_MyShape_t=&m_MyRect_t;
}
*/
}
CLq01Doc::~CLq01Doc()
{
}
BOOL CLq01Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_nColor=ID_COLOR_BLACK-ID_COLOR_BLACK;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CLq01Doc serialization
void CLq01Doc::Serialize(CArchive& ar)
{
/*
int iPos;
for (iPos=0;iPos<GetShapeCount();iPos++)
{
CShape * pShape=GetShape(iPos);
pShape->Serialize (ar);
}
*/
m_iShapes.Serialize (ar);
}
/////////////////////////////////////////////////////////////////////////////
// CLq01Doc diagnostics
#ifdef _DEBUG
void CLq01Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CLq01Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLq01Doc commands
UINT CLq01Doc::GetColor()
{
return ID_COLOR_BLACK+m_nColor;
}
void CLq01Doc::OnColorBlack()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_BLACK-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorBlack(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_BLACK?1:0);
}
void CLq01Doc::OnColorBlue()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_BLUE-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorBlue(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_BLUE?1:0);
}
void CLq01Doc::OnColorCyan()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_CYAN-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorCyan(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_CYAN?1:0);
}
void CLq01Doc::OnColorGreen()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_GREEN-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorGreen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_GREEN?1:0);
}
void CLq01Doc::OnColorRed()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_RED-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorRed(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_RED?1:0);
}
void CLq01Doc::OnColorMagenta()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_MAGENTA-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorMagenta(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_MAGENTA?1:0);
}
void CLq01Doc::OnColorWhite()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_WHITE-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorWhite(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_WHITE?1:0);
}
void CLq01Doc::OnColorYellow()
{
// TODO: Add your command handler code here
m_nColor=ID_COLOR_YELLOW-ID_COLOR_BLACK;
}
void CLq01Doc::OnUpdateColorYellow(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (GetColor()==ID_COLOR_YELLOW?1:0);
}
void CLq01Doc::OnShapeLine()
{
// TODO: Add your command handler code here
m_nShape=0;
}
void CLq01Doc::OnUpdateShapeLine(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (m_nShape==0);
}
void CLq01Doc::OnShapeRectangle()
{
// TODO: Add your command handler code here
m_nShape=1;
}
void CLq01Doc::OnUpdateShapeRectangle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck (m_nShape==1);
}
CShape* CLq01Doc::AddShape(CPoint ptStart, CPoint ptEnd, COLORREF iColor)
{
if(m_nShape==0)
{
CLine *pLine=new CLine(ptStart,ptEnd,m_crColors[m_nColor]);
try
{
m_iShapes.Add (pLine);
SetModifiedFlag();
}
catch (CMemoryException * perr)
{
AfxMessageBox("Out of memory",MB_ICONSTOP | MB_OK);
if (pLine)
{
delete pLine;
pLine=NULL;
}
perr->Delete ();
}
return pLine;
}
else
{
CMyRect *pRect=new CMyRect(ptStart,ptEnd,m_crColors[m_nColor]);
try
{
m_iShapes.Add (pRect);
SetModifiedFlag();
}
catch (CMemoryException * perr)
{
AfxMessageBox("Out of memory",MB_ICONSTOP | MB_OK);
if (pRect)
{
delete pRect;
pRect=NULL;
}
perr->Delete ();
}
return pRect;
}
}
int CLq01Doc::GetShapeCount()
{
return m_iShapes.GetSize ();
}
CShape * CLq01Doc::GetShape(int nIndex)
{
return (CShape*) m_iShapes[nIndex];
}
int CLq01Doc::GetShape()
{
return m_nShape;
}
CShape * CLq01Doc::CreatShape(CPoint ptStart, CPoint ptEnd,COLORREF iColor)
{
if(m_nShape==0)
{
CLine *pLine=new CLine(ptStart,ptEnd,m_crColors[m_nColor]);
return pLine;
}
else
{
CMyRect *pRect=new CMyRect(ptStart,ptEnd,m_crColors[m_nColor]);
return pRect;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -