www.pudn.com > CH4-1.rar > Canvasframe.cpp
// canvasFrame.cpp : implementation file
//
#include "stdafx.h"
#include "canvasr.h"
#include "canvasFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// canvasFrame
IMPLEMENT_DYNCREATE(canvasFrame, CFrameWnd)
int x=0,y=0,vx=21,vy=21;
canvasFrame::canvasFrame()
{
Create(NULL,"»æÍ¼´°¿Ú");
CClientDC dc(this);
int width = dc.GetDeviceCaps(HORZRES);
int height = dc.GetDeviceCaps(VERTRES);
GetWindowRect( &rect );
width = ( width - ( rect.right - rect.left ))/2 ;
height = (height - (rect.bottom - rect.top ))/2 ;
MoveWindow( width , height , (rect.right - rect.left ) , (rect.bottom - rect.top ) ,true);
GetClientRect(&rect);
mdc = new CDC;
mdc->CreateCompatibleDC(&dc);
ball = new CBitmap;
ball->m_hObject = (HBITMAP)::LoadImage(NULL,"ball.bmp",IMAGE_BITMAP,81,81,LR_LOADFROMFILE);
mdc->SelectObject(ball);
}
canvasFrame::~canvasFrame()
{
delete mdc;
delete ball;
}
BEGIN_MESSAGE_MAP(canvasFrame, CFrameWnd)
//{{AFX_MSG_MAP(canvasFrame)
ON_WM_TIMER()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// canvasFrame message handlers
void canvasFrame::OnTimer(UINT nIDEvent)
{
CFrameWnd::OnTimer(nIDEvent);
CClientDC dc(this);
dc.BitBlt(x,y,81,81,mdc,0,0,SRCCOPY);
x += vx;
y += vy;
if(y+60 > rect.bottom)
{
vy = -vy;
y = rect.bottom -60;
}
if(x+60 > rect.right)
{
vx = -vx;
x = rect.right -60;
}
if(y < -21)
{
vy = -vy;
y = -21;
}
if(x < -21)
{
vx = -vx;
x =- 21;
}
}
int canvasFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
SetTimer(1,0,NULL);
return 0;
}