📄 childview.cpp
字号:
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include "MFC.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView::CChildView()
{
m_nLines = 0;
m_aPens[0].CreatePen(PS_DASH,1,RGB(0,0,255));
m_aPens[1].CreatePen(PS_SOLID,4,RGB(255,0,0));
m_aPens[2].CreatePen(PS_SOLID,8,RGB(0,255,0));
m_nPenIndex = 0;
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_CHAR()
ON_WM_MBUTTONDBLCLK()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
for(int i = 0;i<m_nLines;i++)
m_apLines[i] -> Draw(&dc);
// Do not call CWnd::OnPaint() for painting messages
}
void CChildView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
static bool bFirst = true;
static CPoint firstPoint;
if (m_nLines < MAX_LINES)
{
if (bFirst)
{
firstPoint = point;
}
else
{
m_apLines[m_nLines++] = new CLine(firstPoint,point,&m_aPens[m_nPenIndex]);
Invalidate(false);
}
bFirst = !bFirst;
}
//CWnd ::OnLButtonDown(nFlags, point);
}
void CChildView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (nChar >= '1' && nChar <= '3')
{
m_nPenIndex = nChar - '1';
}
else if (nChar == '\b')
{
if(m_nLines > 0)
{
delete m_apLines[--m_nLines];
Invalidate();
}
}
//CWnd ::OnChar(nChar, nRepCnt, nFlags);
}
void CChildView::OnMButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
for (int i = 0;i<m_nLines;i++)
delete m_apLines[i];
m_nLines = 0;
Invalidate();
//CWnd ::OnMButtonDblClk(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -