[游戏模版11] Win32 动画 时间消息
>_<:This time we will study a new way to operate your picture.That is running your picture by give it a timer-message.
>_<:Firstly,you should use the function SetTimer(hWnd,1,50,NULL) to create and set a timer (here "1" means the timer is number 1,you can understand it as the timer's name; "50" means frequency)
>_<:Then only need to add timer-message listener in WndProc(...) function:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int i; switch (message) //判断消息类型
{
case WM_TIMER: //时间消息
MyPaint(hdc);
break;
case WM_DESTROY: //处理窗口结束消息
DeleteDC(mdc);
ReleaseDC(hWnd,hdc);
for(i=;i<;i++)
DeleteObject(girl[i]);
KillTimer(hWnd,);
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
}
>_<:And now function MyPaint(...) will be carryed out at stated times.

>_<:code:picture resource
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by FE.RC
//
#define IDR_MAINFRAME 128
#define IDD_FE_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_FE 107
#define IDI_SMALL 108
#define IDC_FE 109
#define IDC_MYICON 2
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
resourse.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
// #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files:
#include <windows.h> // C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h> // Local Header Files // TODO: reference additional headers your program requires here //{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
StdAfx.h
#include "stdafx.h"
#include "resourse.h"
#include "stdio.h"
#include "time.h" #define MAX_LOADSTRING 100 // Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
HBITMAP girl[];
HDC mdc,hdc;
int num; // Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void MyPaint(HDC hdc);
//========================================================================================
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg; MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码; // 调用InitInstance函数,进行初始化操作;
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} // 消息循环(通过消息循环来获取信息,
//进行必要的键盘信息转换而后将控制权交给操作系统,
//有操作系统决定哪个程序的消息处理函数处理消息
while (GetMessage(&msg, NULL, , )) //获取程序消息
{
TranslateMessage(&msg);//转换伪码及字符
DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
} return msg.wParam;
}
//===================================================================================== //=============================================================================================
//在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
//并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
//==============================================================================================
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
//--------------------------------------------------------------
//定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
//为WNDPROC,类别名称为(lpszClassName)为”fe";
//--------------------------------------------------------------
wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = ;
wcex.cbWndExtra = ;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "fe";
wcex.hIconSm = NULL; return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
//此字符串即为类别名称”fe";
}
//============================================================================================ //============================================================================================
//按照前面所定义的窗口类别来建立并显示实际的程序窗口
//============================================================================================
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
char filename[]="";
int i;
hInst = hInstance; // 把instance handle 储存在全局变量中; hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL);
//-----------------------------------------------
//调用CreateWindow函数来建立一个窗口对象
//第一个参数就是窗口建立依据的类别名称
//-----------------------------------------------
if (!hWnd)
{
return FALSE;
}
//------------------------------------------------
//设定窗口的位置及窗口的大小,然后绘制显示在设备上
//-------------------------------------------------
MoveWindow(hWnd,,,,,true);//位置及大小
ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
UpdateWindow(hWnd);//将窗口绘制在显示设备上 hdc=GetDC(hWnd);
mdc=CreateCompatibleDC(hdc); for(i=;i<;i++)
{
sprintf(filename,"map%d.bmp",i);
girl[i]=(HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,,,LR_LOADFROMFILE);
} num=;
SetTimer(hWnd,,,NULL);
srand((unsigned)time(NULL)); MyPaint(hdc); return TRUE;
}
//============================================================================================ //============================================================================================
//
//============================================================================================
void MyPaint(HDC hdc)
{
if(num>)num=;
for(int j=;j<;j++)
{
SelectObject(mdc,girl[ rand()%]);
BitBlt(hdc,*(j%),j/*,,,mdc,,,SRCCOPY);
}
num++;
}
//============================================================================================ //============================================================================================
//在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
//来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
//程序都会接收信息,选择性接受、处理;
//============================================================================================
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int i; switch (message) //判断消息类型
{
case WM_TIMER: //时间消息
MyPaint(hdc);
break;
case WM_DESTROY: //处理窗口结束消息
DeleteDC(mdc);
ReleaseDC(hWnd,hdc);
for(i=;i<;i++)
DeleteObject(girl[i]);
KillTimer(hWnd,);
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
}
//============================================================================================
main.cpp
[游戏模版11] Win32 动画 时间消息的更多相关文章
- [游戏模版12] Win32 稳定定时
>_<:The last time,we learned how to use timer to make the picture run and change show,but some ...
- [游戏模版13] Win32 透明贴图 主角移动
>_<:just add previous two ways to achieve this new result // stdafx.h : include file for stand ...
- [游戏模版2] Win32最小框架
>_<:Just the minimum Win32 frame don't have any other special function. //{{NO_DEPENDENCIES}} ...
- [游戏模版14] Win32 键盘控制
>_<:compared with the previous article,this one only adds key-message listener. >_<:up d ...
- [游戏模版18] Win32 五子棋
>_<:Learning its AI logic. >_<:resource >_<:code: #include <windows.h> // C ...
- [游戏模版20] Win32 物理引擎 加速运动
>_<:Compared with previous talk,there will be taking about how to create an accelerated speed. ...
- [游戏模版21] Win32 物理引擎 能量守恒
>_<:Only a little change in the function of MyPaint(...),besides the initial value have some c ...
- [游戏模版3] Win32 画笔 画刷 图形
>_<:introduce the functions of define\create\use pen and brush to draw all kinds of line and s ...
- [游戏模版4] Win32 显示鼠标位置
>_<:use MOUSE_MOVE message refresh the position information. >_<:use LOWORD(lParam) get ...
随机推荐
- JavaScript valueOf() 函数详解
valueOf()函数用于返回指定对象的原始值. 该方法属于Object对象,由于所有的对象都"继承"了Object的对象实例,因此几乎所有的实例对象都可以使用该方法. 所有主流浏 ...
- Brn系列网上商城数据库说明文档
单店版BrnShop_1.9.351数据字典:点击下载 多店版BrnMall_1.9.496数据字典:点击下载 有对网上商城程序设计感兴趣的朋友,欢迎加入QQ群:235274151,大家可以交流下!
- oracle 客户端重新安装遇到的问题
前一阵,因为把ORACLE客户端的密码忘记了,在网上也找了好多方法,试着不重新安装找回密码,可是都行不通,没有办法重新装.安装时遇到一些问题,因为我是WIN7,64位系统,安装的oracle11g64 ...
- linux 错误处理
linux程序设计中,有许多系统调用和函数会因为各种原因而失败.在失败时设置外部变量errno的值来指明失败原因.程序必须在函数报告出错之后立即检查errno变量,因为它可能被下一个函数调用所覆盖(外 ...
- 博客的开端,找对象不再new
今天是第一次用blog,小白开始完善了!! 希望大家多多照顾一下.
- 如何用expdp、impdp按表空间导出、导入?
参考:http://blog.csdn.net/zftang/article/details/6387325 A数据库: 表空间:ylcois 用户名:ylcois 密码:ylcois B数据库: 表 ...
- 测试table数据 winfrom datagridview 点击标头数字排序的时候table 列类型要为数字类型
public DataTable GenerateData(int NoOfRecord){DataTable tbl = new DataTable();tbl.Columns.Add(new Da ...
- 千人基因组计划数据库下载某段区域SNP
进入http://browser.1000genomes.org/index.html网站 假定要寻找“6:133098746-133108745”这段距离的SNP数据,“6”表示6号染色体,后面的数 ...
- AS错误:Please configure your build for VectorDrawableCompat.
运行第一个Android Stdio程序就出现下面这个问题,由于对Android Stdio不熟悉整了三个小时才解决,希望这篇博客能帮助更多的人. 问题:Caused by:java.lang.Run ...
- Photoshop 使用可选颜色
CMYK 由 青色(Cyan) 洋红(Magenta)黄色(Yellow)黑色(Key Plate)组成, 他们和三基色 红绿蓝 RGB 关系如下 如图 红色 = 品红 + 黄色 绿色 = 黄色 + ...