📄 turnoutview.cpp
字号:
// TurnOutView.cpp : implementation of the CTurnOutView class
//
#include "stdafx.h"
#include "TurnOut.h"
#include "TurnOutDoc.h"
#include "TurnOutView.h"
#include "Turnoff.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
Turnoff T1,T2;
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView
IMPLEMENT_DYNCREATE(CTurnOutView, CView)
BEGIN_MESSAGE_MAP(CTurnOutView, CView)
//{{AFX_MSG_MAP(CTurnOutView)
ON_WM_LBUTTONDOWN()
ON_WM_TIMER()
ON_WM_RBUTTONDOWN()
ON_WM_CREATE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView construction/destruction
CTurnOutView::CTurnOutView()
{
// TODO: add construction code here
}
CTurnOutView::~CTurnOutView()
{
}
BOOL CTurnOutView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView drawing
void CTurnOutView::OnDraw(CDC* pDC)
{
CTurnOutDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC *pMemDC;
CBitmap *myBitmap;
CPen *myPen;
myBitmap=new CBitmap;//建立位图
pMemDC=new CDC;//建立内存设备
myPen=new CPen;//建立画笔
pMemDC->CreateCompatibleDC(pDC);//建立和显示设备兼容的内存设备
myBitmap->CreateCompatibleBitmap(pDC,1440,864);//建立和显示设备大小相同的位图
CBitmap *oldBitmap=pMemDC->SelectObject(myBitmap);//选入兼容位图并追踪原来位图
CPen *oldPen=pMemDC->SelectObject(myPen);//选入画笔并追踪
pMemDC->FillSolidRect(0,0,1440,864,RGB(255,255,255));//画背景
T1.DrawG(pMemDC,10,flag_color);
if (T1.B_Position==T1.N_Position)
T1.Draw_Usual(pMemDC,10,flag_color);
else
T1.Draw(pMemDC,10,flag_color);
//pDC->BitBlt(0,0,1152,864,pMemDC,0,0,SRCCOPY);//拷贝进显示设备
pDC->StretchBlt(0,0,1440,864,pMemDC,0,0,1440,864,SRCCOPY);
pMemDC->SelectObject(oldPen);//还原
pMemDC->SelectObject(oldBitmap);//还原
ReleaseDC(pDC);
ReleaseDC(pMemDC);
delete myBitmap;
delete pMemDC;
delete myPen;//清理工作
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView printing
BOOL CTurnOutView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTurnOutView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTurnOutView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView diagnostics
#ifdef _DEBUG
void CTurnOutView::AssertValid() const
{
CView::AssertValid();
}
void CTurnOutView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTurnOutDoc* CTurnOutView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTurnOutDoc)));
return (CTurnOutDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTurnOutView message handlers
BOOL CTurnOutView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
T1.GX1=100;
T1.GX2=150;
T1.GY1=T1.GY2=200;
T1.DX1=200;
T1.DY1=200;
T1.FX1=180;
T1.FY1=210;
T1.B_Position=T1.N_Position="d";
T2.GX1=250;
T2.GX2=300;
T2.GY1=T2.GY2=200;
T2.DX1=350;
T2.DY1=200;
T2.FX1=330;
T2.FY1=210;
T2.B_Position=T2.N_Position="d";
flag_color=0;
flag_T1_B=flag_T1_N=10;
//
return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void CTurnOutView::OnLButtonDown(UINT nFlags, CPoint point)
{
static int i=0;
if(i%2==0)
{
T1.N_Position="f";
}
else
{
T1.N_Position="d";
}
i++;
CView::OnLButtonDown(nFlags, point);
}
void CTurnOutView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
flag_color++;
CView::OnTimer(nIDEvent);
switch(nIDEvent)
{
case 1:
{
Invalidate(NULL);
break;
}
}
/* if(nIDEvent==2)
{
//if(flag_T1_N>=0)
// if(flag_T1_N<0)
//
if(flag_T2_N>=0)
flag_T2_N--;
}//*/
}
void CTurnOutView::OnRButtonDown(UINT nFlags, CPoint point)
{
SetTimer(2,2000,NULL);
static int i=0;
//设定标志flag_T2
if(i%2==0)
{
// T1.N_Position="f";
T2.N_Position="f";
}
else
{
// T1.N_Position="d";
T2.N_Position="d";
}
i++;
CView::OnRButtonDown(nFlags, point);
}
int CTurnOutView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
SetTimer(1,100,NULL);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -