?? 專周view.cpp
字號:
// 專周View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "專周.h"
#include "專周Doc.h"
#include "專周View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_WM_KEYDOWN()
ON_COMMAND(ID_Start, OnStart)
ON_COMMAND(ID_End, OnEnd)
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetClientRect(&rect);
CBrush BkgBrush(RGB(0,255,0));
pDC->FillRect(rect,&BkgBrush);//背景色
pDC->SelectStockObject(BLACK_BRUSH);
pDC->Rectangle(pDoc->m_rectBody);//底版的顏色
CBrush Ballse,*ballse;
Ballse.CreateSolidBrush(RGB(0,100,100));
ballse=pDC->SelectObject(&Ballse);
pDC->Ellipse(pDoc->m_rectBall);
pDC->SelectObject(Ballse);//球的顏色
CBrush brushNewRed,brushNewBlue,*pbrushOld;
brushNewRed.CreateSolidBrush(RGB(255,0,0));
brushNewBlue.CreateSolidBrush(RGB(0,0,255));
pbrushOld=pDC->SelectObject(&brushNewRed);//畫刷
CRect rect1;
GetClientRect(&rect1);
CRect block[C_XBLOCKS][C_YBLOCKS];
int xDim;
int yDim;
xDim = rect.Width();
yDim = rect.Height();
int iBlockWidth;
int iBlockHeight;
iBlockWidth = (int)xDim/(C_XBLOCKS );
iBlockHeight = (int)((yDim/5)/C_YBLOCKS);
for(int i=0;i<= C_XBLOCKS;i++)
{
for (int j=0;j<=C_YBLOCKS;j++)
{
block[i][j].left=(int)(i*iBlockWidth);
block[i][j].right=block[i][j].left+iBlockWidth;
block[i][j].top = (int)(j*iBlockHeight + 20);
block[i][j].bottom = block[i][j].top + iBlockHeight;
pDC->Rectangle(block[i][j]);
if(j==0 || j==2 )
{pDC->SelectObject(&brushNewRed);}
else
{pDC->SelectObject(&brushNewBlue);}
if(pDoc->m_nCount[i][j]==0)
{ pDC->Rectangle(pDoc->block[i][j]);}
else break;
}
}
// pDC->SelectObject(pbrushOld);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rectClient;
GetClientRect(&rectClient);
InvalidateRect(pDoc->m_rectBody,TRUE);
switch(nChar)
{
case VK_LEFT:
if( pDoc->m_rectBody.left>rectClient.left )
{
pDoc->m_rectBody.left-=15;
pDoc->m_rectBody.right-=15;
}
break;
case VK_RIGHT:
if( pDoc->m_rectBody.right<rectClient.right )
{
pDoc->m_rectBody.left+=15;
pDoc->m_rectBody.right+=15;
}
break;
}
InvalidateRect(pDoc->m_rectBody,FALSE);
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMyView::OnStart()
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_nStart=1;
SetTimer(1,100,NULL);
// TODO: Add your command handler code here
}
void CMyView::OnEnd()
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_nStart=0;
KillTimer(1);
// TODO: Add your command handler code here
}
void CMyView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
InvalidateRect(pDoc->m_rectBall,TRUE);
CRect rect1;
GetClientRect(&rect1);
if(pDoc->m_rectBall.right>=rect1.right || pDoc->m_rectBall.left<=rect1.left)
{pDoc->m_nx=-pDoc->m_nx;}
else ;
if(pDoc->m_rectBall.top<=rect1.top || pDoc->m_rectBall.left>pDoc->m_rectBody.left && pDoc->m_rectBall.right<pDoc->m_rectBody.right && pDoc->m_rectBall.bottom>pDoc->m_rectBody.top)
{pDoc->m_ny=-pDoc->m_ny;}
pDoc->m_rectBall.left-=pDoc->m_nx;
pDoc->m_rectBall.right-=pDoc->m_nx;
pDoc->m_rectBall.top-=pDoc->m_ny;
pDoc->m_rectBall.bottom-=pDoc->m_ny;
InvalidateRect(pDoc->m_rectBall,FALSE);
int i,j;
for(i=0;i<C_XBLOCKS;i++)
{
for (j=0;j<C_YBLOCKS;j++)
{if(pDoc-> m_nCount[i][j]==0)
{ if(pDoc->m_rectBall.left>pDoc->block[i][j].left&& pDoc->m_rectBall.right<pDoc->block[i][j].right && pDoc->m_rectBall.top<pDoc->block[i][j].bottom)
{
{pDoc->m_ny=-pDoc->m_ny;}
pDoc->m_rectBall.left-=pDoc->m_nx;
pDoc->m_rectBall.right-=pDoc->m_nx;
pDoc->m_rectBall.top-=pDoc->m_ny;
pDoc->m_rectBall.bottom-=pDoc->m_ny;
pDoc-> m_nCount[i][j]=1;
InvalidateRect(pDoc->block[i][j],TRUE);
}
}
}
}
CView::OnTimer(nIDEvent);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -