| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 484 人关注过本帖
标题:LOVE
只看楼主 加入收藏
coding
Rank: 1
等 级:新手上路
威 望:1
帖 子:60
专家分:0
注 册:2007-9-30
收藏
 问题点数:0 回复次数:0 
LOVE


//这是主文件Game.cpp
这是动画的主PROGRAM,我花啦一个晚上着的,
#include "Game.h"
#include "resource.h"
#include "math.h"
#include "string.h"
BEGIN_MESSAGE_MAP(CGameWnd,CFrameWnd)
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_CREATE()
END_MESSAGE_MAP()

CGameWnd::CGameWnd()
{
m_cpbobstep.x=8;
m_cpbobstep.y=0;
m_cpmarrystep.x=-8;
m_cpmarrystep.y=0;
/*CRect rc;
GetClientRect(&rc);
m_cpbob.x=rc.left;
m_cpbobstep.y=rc.bottom/2;
m_cpmarry.x=rc.right;
m_cpmarry.y=rc.bottom/2;*/
m_cpbob.x=10;
m_cpbob.y=200;
m_cpmarry.x=500;
m_cpmarry.y=200;
flag=FALSE;
}

CGameWnd::~CGameWnd()
{
}

BOOL CGameWnd::PreCreateWindow(CREATESTRUCT &cs)
{
// m_hIconbob=(HICON)::LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON2));
//m_hIconmarry=(HICON)::LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON1));
m_hIconpro=(HICON)::LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON3));
m_hIconbob=(HICON)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDI_ICON2),
IMAGE_ICON,48,48,LR_DEFAULTCOLOR);
m_hIconmarry=(HICON)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDI_ICON1),
IMAGE_ICON,48,48,LR_DEFAULTCOLOR);
m_hIconlove=(HICON)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDI_ICON4),
IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
m_hIconbobstand=(HICON)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDI_ICON5),
IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
m_hIconmarrywave=(HICON)::LoadImage(cs.hInstance,MAKEINTRESOURCE(IDI_ICON6),
IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
return CFrameWnd::PreCreateWindow(cs);
}

int CGameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (m_hIconpro)
{
SetIcon(m_hIconpro,TRUE);
SetIcon(m_hIconpro,FALSE);
}
return 0;
}

void CGameWnd::OnDraw(CClientDC* pdc)
{
LOGFONT lf;
CFont fnt;
CFont* oldfnt;
lf.lfWidth=10;
lf.lfHeight=50;
lf.lfWeight=70;
lf.lfOrientation=0;
lf.lfEscapement=0;
lf.lfItalic=FALSE;
lf.lfUnderline=FALSE;
lf.lfStrikeOut=FALSE;
strcpy(lf.lfFaceName,"黑体");
fnt.CreateFontIndirect(&lf);
CString str,str1;
CRect rc;
GetClientRect(&rc);
str.Format("m:x=%d y=%d", m_cpmarry.x,m_cpmarry.y);
str1.Format("b:x=%d y=%d",m_cpbob.x,m_cpbob.y);
pdc->TextOut(0,10,str);
pdc->TextOut(0,30,str1);
pdc->SetBkColor(RGB(255,200,0));
if (flag==FALSE)
{
pdc->DrawIcon(m_cpbob.x,m_cpbob.y,m_hIconbobstand);
pdc->DrawIcon(m_cpmarry.x,m_cpmarry.y,m_hIconmarry);
flag=TRUE;
}
else
{
pdc->DrawIcon(m_cpbob.x,m_cpbob.y,m_hIconbob);
pdc->DrawIcon(m_cpmarry.x,m_cpmarry.y,m_hIconmarrywave);
flag=FALSE;
}

if (m_cpbobstep.x*m_cpmarrystep.x<0)
if ((m_cpbob.x+m_cpmarry.x)>rc.Width())

pdc->TextOut(m_cpmarry.x,m_cpmarry.y-100,"Welcome");
else
pdc->TextOut(m_cpmarry.x,m_cpmarry.y-100,"goodbye!");
oldfnt=pdc->SelectObject(&fnt);
if (abs(m_cpbob.x-m_cpmarry.x)<10)
{
pdc->SetTextColor(RGB(255,0,0));
pdc->DrawIcon(m_cpbob.x,m_cpbob.y-10,m_hIconlove);
pdc->TextOut(m_cpbob.x,m_cpbob.y-100,"bob ,i love you too!");
pdc->TextOut(m_cpbob.x,m_cpbob.y+100,"marry ,i love you !");
MessageBeep(MB_OK);
Sleep(1000);
}


pdc->TextOut(m_cpbob.x,m_cpbob.y+100,"marry ,i love you!");
pdc->SelectObject(oldfnt);


}

void CGameWnd::OnPaint()
{
CFrameWnd::OnPaint();
CRect rc;
GetClientRect(&rc);
CClientDC dc(this);
OnDraw(&dc);
m_cpbob.x+=m_cpbobstep.x;
m_cpmarry.x+=m_cpmarrystep.x;
if(m_cpbob.x<0||m_cpbob.x>(rc.right))
m_cpbobstep=-m_cpbobstep;
if(m_cpmarry.x<0||m_cpmarry.x>(rc.right))
m_cpmarrystep=-m_cpmarrystep;
ReleaseDC(&dc);

}

void CGameWnd::OnTimer(UINT nIDEvent)
{
Invalidate();

}

BOOL CGameApp::InitInstance()
{
CGameWnd* pFrame=new CGameWnd;
pFrame->Create(0,"coding");
pFrame->ShowWindow(SW_SHOWNORMAL);
pFrame->UpdateData();
pFrame->SetTimer(1,100,NULL);
this->m_pMainWnd=pFrame;
return TRUE;
}

CGameApp theApp;

搜索更多相关主题的帖子: LOVE 
2007-10-08 10:10
快速回复:LOVE
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025379 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved