📄 ddutil.h
字号:
//-----------------------------------------------------------------------------
// File: ddutil.cpp
//
// Desc: Routines for loading bitmap and palettes from resources
//
// Copyright (C) 1998-1999 Microsoft Corporation. All Rights Reserved.
//-----------------------------------------------------------------------------
#ifndef DDUTIL_H
#define DDUTIL_H
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } //释放对象的宏
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
#include <ddraw.h>
//-----------------------------------------------------------------------------
// Classes defined in this header file
//-----------------------------------------------------------------------------
class CDisplay; //DirectX对象类
class CSurface; //平面对象类
//-----------------------------------------------------------------------------
// Name: class CDisplay
// Desc: Class to handle all DDraw aspects of a display, including creation of
// front and back buffers, creating offscreen surfaces and palettes,
// and blitting surface and displaying bitmaps.
//-----------------------------------------------------------------------------
class CDisplay
{
protected:
LPDIRECTDRAW7 m_pDD; //DirectX对象
LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer; //DirectX对象的前平面对象
LPDIRECTDRAWSURFACE7 m_pddsBackBuffer; //DirectX对象的后平面对象
HWND m_hWnd; //窗口的句柄
public:
CDisplay();
~CDisplay();
// 返回DirectX实例对应的DirectX对象
LPDIRECTDRAW7 GetDirectDraw() { return m_pDD; }
//创建DirectX对象
HRESULT Create( HWND hWnd, DWORD dwWidth, DWORD dwHeight,
DWORD dwBPP );
virtual HRESULT DestroyObjects(); //释放DirectX对象
//创建位图平面
HRESULT CreateSurfaceFromBitmap( CSurface** ppSurface, TCHAR* strBMP,
DWORD dwDesiredWidth,
DWORD dwDesiredHeight );
//创建文字平面
HRESULT CreateSurfaceFromText( CSurface** ppSurface, HFONT hFont,
TCHAR* strText,
COLORREF crBackground,
COLORREF crForeground );
//清除屏幕
HRESULT Clear( DWORD dwColor = 0L );
//将表面对象显示在屏幕上
HRESULT Blt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
RECT* prc, DWORD dwFlags=0 );
//将平面实例显示到屏幕上
HRESULT Blt( DWORD x, DWORD y, CSurface* pSurface, RECT* prc );
//显示缓存平面的内容(交换前后平面)
HRESULT Present();
};
//-----------------------------------------------------------------------------
// Name: class CSurface
// Desc: Class to handle aspects of a DirectDrawSurface.
//-----------------------------------------------------------------------------
class CSurface
{
LPDIRECTDRAWSURFACE7 m_pdds; //平面对象
DDSURFACEDESC2 m_ddsd; //平面结构
BOOL m_bColorKeyed; //是否使用透明颜色
DWORD dwWidth; //表面的有效宽度和高度
DWORD dwHeight;
public:
LPDIRECTDRAWSURFACE7 GetDDrawSurface() { return m_pdds; } //返回平面对象
BOOL IsColorKeyed() { return m_bColorKeyed; }//返回是否使用透明颜色
DWORD GetWidth() { return dwWidth; } //返回表面的有效宽度和高度
DWORD GetHeight() { return dwHeight; }
HRESULT DrawBitmap( HBITMAP hBMP ); //在表面画位图
HRESULT DrawBitmap( TCHAR* strBMP );
HRESULT DrawText( HFONT hFont, TCHAR* strText, //在平面设置文字
COLORREF crBackground, COLORREF crForeground );
HRESULT SetColorKey( COLORREF crColorKey ); //设置透明颜色
HRESULT Create( LPDIRECTDRAW7 pDD, DDSURFACEDESC2* pddsd ); //创建表面对象
CSurface();
~CSurface();
};
#endif // DDUTIL_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -