📄 movetestview.cpp
字号:
// MoveTestView.cpp : implementation of the CMoveTestView class
//
#include "stdafx.h"
#include "MoveTest.h"
#include "MoveTestDoc.h"
#include "MoveTestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView
IMPLEMENT_DYNCREATE(CMoveTestView, CView)
BEGIN_MESSAGE_MAP(CMoveTestView, CView)
//{{AFX_MSG_MAP(CMoveTestView)
ON_COMMAND(ID_GRAPH_MOVE, OnGraphMove)
ON_COMMAND(ID_GRAPH_TRACK, OnGraphTrack)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView construction/destruction
CMoveTestView::CMoveTestView()
{
// TODO: add construction code here
drawtrack=false;
pointlisthead =NULL;
}
CMoveTestView::~CMoveTestView()
{
}
BOOL CMoveTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView drawing
void CMoveTestView::OnDraw(CDC* pDC)
{
CMoveTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView printing
BOOL CMoveTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMoveTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMoveTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView diagnostics
#ifdef _DEBUG
void CMoveTestView::AssertValid() const
{
CView::AssertValid();
}
void CMoveTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMoveTestDoc* CMoveTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMoveTestDoc)));
return (CMoveTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMoveTestView message handlers
void CMoveTestView::OnGraphMove()
{
// TODO: Add your command handler code here
flag="move";
MoveObject();
}
void CMoveTestView::OnGraphTrack()
{
// TODO: Add your command handler code here
flag="track";
}
void CMoveTestView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(flag=="track")
{
struct pointstruct *temppoint;
while(pointlisthead)
{
temppoint = pointlisthead;
pointlisthead = pointlisthead->next;
delete temppoint;
}
drawtrack=true;
}
CView::OnLButtonDown(nFlags, point);
}
void CMoveTestView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(drawtrack)
{
drawtrack=false;
}
CView::OnLButtonUp(nFlags, point);
}
void CMoveTestView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(drawtrack)
{
CClientDC dc(this);
dc.SetPixel(point.x,point.y,RGB(0,0,0));
struct pointstruct *newpoint=new struct pointstruct;
newpoint->point.x=point.x;
newpoint->point.y=point.y;
newpoint->next=NULL;
if(pointlisthead==NULL)
{
pointlisthead=pointlisttrail=newpoint;
}
else
{
pointlisttrail->next=newpoint;
pointlisttrail=newpoint;
}
}
CView::OnMouseMove(nFlags, point);
}
void CMoveTestView::MoveObject()
{
struct pointstruct *pointtemp=pointlisthead;
int i=1;
CPoint pointold;
BOOL first=true;
while(pointtemp)
{
CClientDC dc(this);
CDC *memdc=new CDC;
memdc->CreateCompatibleDC(&dc);
if(!first)
{
CBitmap bitmap1;
if(i%2==0)
bitmap1.LoadBitmap(IDB_BIT1);
else
bitmap1.LoadBitmap(IDB_BIT2);//DSTINVERT
memdc->SelectObject(&bitmap1);
dc.BitBlt(pointold.x-24,pointold.y-24,48,48,memdc,0,0,PATPAINT);
}
else
first=false;
CBitmap bitmap;
if(i%2)
bitmap.LoadBitmap(IDB_BIT1);
else
bitmap.LoadBitmap(IDB_BIT2);
memdc->SelectObject(&bitmap);
dc.BitBlt(pointtemp->point.x-24,pointtemp->point.y-24,48,48,memdc,0,0,SRCAND);
pointold.x=pointtemp->point.x;
pointold.y=pointtemp->point.y;
delete memdc;
pointtemp=pointtemp->next;
i++;
for(int j=0;j<5000000;j++)
;
}
pointtemp=pointlisthead;
while(pointtemp)
{
CClientDC dc(this);
dc.SetPixel(pointtemp->point.x,pointtemp->point.y,RGB(0,0,0));
pointtemp=pointtemp->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -