这次,主要就是利用前面几篇博客里面的例子,来做几个应用练习,主要就是,让图片闪烁,一次读取多张图片,和使用随机数随机读取图片(当然,这里的随机数用的是C语言,而不是C++的随机数引擎,但是原理是一样的),这次,我把我的代码工程上传上来,希望大家下载学习,毕竟 里面会涉及到一些资源问题,把代码复制去了,改起来挺麻烦也。地址:http://download.youkuaiyun.com/detail/shangdi712/7704977
//Utility.h
#ifndef WINDOWS_USEFUL_TOOLS_
#define WINDOWS_USEFUL_TOOLS_
#include <Windows.h>
#include <MMSystem.h>
#pragma comment(lib,"Winmm.lib")
#include <wchar.h>
#include <time.h>
#endif
#ifndef D3D_USEFUL_TOOLS_
#define D3D_USEFUL_TOOLS_
#include <d3d9.h>
#pragma comment(lib,"d3d9.lib")
#include <d3dx9.h>
#pragma comment(lib,"d3dx9.lib")
#endif
#ifndef SAFE_CLEANUP_
#define SAFE_CLEANUP_
//内联函数模板,参数为 T* 类型的引用
template<typename T>inline void Safe_Delete( T* & p )
{
if(p){ delete p ; p = NULL;}
}
template<typename T>inline void Safe_Release( T* & p )
{
if(p){ p->Release() ; p = NULL;}
}
#endif
#ifndef STL_TOOLS_
#define STL_TOOLS_
#include <vector>
#include <string>
using namespace std;
#endif
#ifdef UNICODE
#define string wstring
#define sprintf_s swprintf_s
#else
#define string string
#define sprintf_s sprintf_s
#endif
//WinMain.cpp
#include "Utility.h"
HWND g_hWnd = 0;
int g_iWidth = 800;
int g_iHeight = 600;
HINSTANCE g_hInstance = 0;
LRESULT CALLBACK WndProc(HWND hWnd ,UINT uMsg,
WPARAM wParam,LPARAM lParam);
LPDIRECT3D9 g_pD3D = nullptr;
LPDIRECT3DDEVICE9 g_pDevice = nullptr;
LPD3DXSPRITE g_pSprite = nullptr; //精灵指针
D3DXMATRIX g_matIdentity; //用于恢复渲染状态的单位矩阵
LPDIRECT3DTEXTURE9 g_pRole = n