📄 barsdemoview.cpp
字号:
// BarsDemoView.cpp : implementation of the CBarsDemoView class
//
#include "stdafx.h"
#include "BarsDemo.h"
#include "BarsDemoDoc.h"
#include "BarsDemoView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBarsDemoView
IMPLEMENT_DYNCREATE(CBarsDemoView, CView)
BEGIN_MESSAGE_MAP(CBarsDemoView, CView)
//{{AFX_MSG_MAP(CBarsDemoView)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBarsDemoView construction/destruction
CBarsDemoView::CBarsDemoView()
{
}
CBarsDemoView::~CBarsDemoView()
{
}
BOOL CBarsDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CBarsDemoView drawing
void CBarsDemoView::OnDraw(CDC* pDC)
{
CBarsDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CWnd *pWnd = pDC->GetWindow();
// Get a pointer to the frame window.
CMainFrame *pFrame =
(CMainFrame *) AfxGetMainWnd();
// Loop through the list of draw events.
for( int i=0; i<pFrame->m_nCurrentDrawEvent; i++ ){
// Copy structure members into local variables
// for clearer code.
COLORREF cColor = pFrame->m_DrawEvent[i].cColor;
int nX1 = pFrame->m_DrawEvent[i].nX1;
int nY1 = pFrame->m_DrawEvent[i].nY1;
int nX2 = pFrame->m_DrawEvent[i].nX2;
int nY2 = pFrame->m_DrawEvent[i].nY2;
// Create a new brush and pen. Select them
// into the dc and remember the old
// pen and brush.
CBrush *pOldBrush, Brush( cColor );
CPen *pOldPen, Pen( PS_SOLID, 1, cColor );
pOldBrush = pDC->SelectObject( &Brush );
pOldPen = pDC->SelectObject( &Pen );
// Create a rect object for the
// rectangle and ellipse operations.
CRect Rect( nX1, nY1, nX2, nY2 );
switch( pFrame->m_DrawEvent[i].nOperation ){
case OPERATION_LINE:
// Draw a line.
pDC->MoveTo( nX1, nY1 );
pDC->LineTo( nX2, nY2 );
break;
case OPERATION_RECTANGLE:
// Draw a rectangle.
pDC->Rectangle( Rect );
break;
case OPERATION_ELLIPSE:
// Draw an ellipse.
pDC->Ellipse( Rect );
break;
}
// Select the old pen and brush back
// into the dc.
pDC->SelectObject( pOldBrush );
pDC->SelectObject( pOldPen );
}
}
/////////////////////////////////////////////////////////////////////////////
// CBarsDemoView diagnostics
#ifdef _DEBUG
void CBarsDemoView::AssertValid() const
{
CView::AssertValid();
}
void CBarsDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CBarsDemoDoc* CBarsDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBarsDemoDoc)));
return (CBarsDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBarsDemoView message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -