📄 myball.cpp
字号:
// MyBall.cpp : implementation file
//
#include "stdafx.h"
#include "playBall.h"
#include "MyBall.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyBall
CMyBall::CMyBall()
{
}
CMyBall::CMyBall(CWnd *pParent, UINT id)
{
m_id = id;
dx = dy = 5;
x = y = 0;
m_pParent = pParent;
}
CMyBall::~CMyBall()
{
}
BEGIN_MESSAGE_MAP(CMyBall, CWnd)
//{{AFX_MSG_MAP(CMyBall)
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
int CMyBall::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CRgn rgn;
rgn.CreateEllipticRgnIndirect(CRect(0, 0, m_rect.Width(), m_rect.Height()));
SetWindowRgn((HRGN)rgn, TRUE);
SetTimer(99, 100 / m_nSpeed, NULL);
srand(rand());
dx = rand() % 9 + 1;
dy = rand() % 9 + 1;
return 0;
}
void CMyBall::OnTimer(UINT nIDEvent)
{
CRect rectParent;
m_pParent->GetClientRect(&rectParent);
if(m_rect.left < rectParent.left ||
m_rect.right > rectParent.right)
dx = -dx;
if(m_rect.top < rectParent.top ||
m_rect.bottom > rectParent.bottom)
dy = -dy;
m_rect.OffsetRect(dx, dy);
MoveWindow(&m_rect);
RedrawWindow();
CWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -