📄 ddutil.h
字号:
//-----------------------------------------------------------------------------
// File: ddutil.cpp
//
// Desc: Routines for loading bitmap and palettes from resources
//
// Copyright (C) 1998-2001 Microsoft Corporation. All Rights Reserved.
//-----------------------------------------------------------------------------
#ifndef DDUTIL_H
#define DDUTIL_H
#include <ddraw.h>
#include <d3d.h>
#include <emmintrin.h>//MMX指令的头文件
//-----------------------------------------------------------------------------
// Classes defined in this header file
//-----------------------------------------------------------------------------
class CDisplay;
class CSurface;
//-----------------------------------------------------------------------------
// Flags for the CDisplay and CSurface methods
//-----------------------------------------------------------------------------
#define DSURFACELOCK_READ
#define DSURFACELOCK_WRITE
//-----------------------------------------------------------------------------
// 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; //directdraw对象,这个7是微软支持的最高版本
LPDIRECTDRAWSURFACE7 m_pddsFrontBuffer; //页面对象,作为表面,也就是在屏幕上显示的
LPDIRECTDRAWSURFACE7 m_pddsBackBuffer; //页面对象,作为内存buff,绘制操作的目标
LPDIRECTDRAWSURFACE7 m_pddsBackBufferLeft; //
DDSURFACEDESC2 ddsd; //用作窗口模式下的
HWND m_hWnd;
RECT m_rcWindow;
BOOL m_bWindowed;
BOOL m_bStereo;
public:
CDisplay();
~CDisplay();
//get函数
HWND GetHWnd() { return m_hWnd; } //
LPDIRECTDRAW7 GetDirectDraw() { return m_pDD; }
LPDIRECTDRAWSURFACE7 GetFrontBuffer() { return m_pddsFrontBuffer; }
LPDIRECTDRAWSURFACE7 GetBackBuffer() { return m_pddsBackBuffer; }
LPDIRECTDRAWSURFACE7 GetBackBufferLeft() { return m_pddsBackBufferLeft; }
//状态函数
BOOL IsWindowed() { return m_bWindowed; }
BOOL IsStereo() { return m_bStereo; }
//创建和释放对象的函数
HRESULT CreateFullScreenDisplay( HWND hWnd, DWORD dwWidth, DWORD dwHeight,
DWORD dwBPP );
HRESULT CreateWindowedDisplay( HWND hWnd, DWORD dwWidth, DWORD dwHeight );
HRESULT InitClipper();
HRESULT UpdateBounds();
virtual HRESULT DestroyObjects();
__m64 Get_m64(__int64 n);
__int64 Get_int64(DWORD dwNum);
// Methods to create child objects
HRESULT CreateSurface( CSurface** ppSurface, DWORD dwWidth,
DWORD dwHeight, DWORD nFlags = DDSCAPS_OFFSCREENPLAIN);
HRESULT CreateSurfaceFromBitmap( CSurface** ppSurface, TCHAR* strBMP,
DWORD dwDesiredWidth,
DWORD dwDesiredHeight,
DWORD nFlags = DDSCAPS_OFFSCREENPLAIN);
HRESULT CreateSurfaceFromBitmap( CSurface** ppSurface, TCHAR* strBMP,DWORD nFlags = DDSCAPS_OFFSCREENPLAIN);
HRESULT CreateSurfaceFromText( CSurface** ppSurface, HFONT hFont,
TCHAR* strText,
COLORREF crBackground,
COLORREF crForeground,
DWORD nFlags = DDSCAPS_OFFSCREENPLAIN);
HRESULT CreatePaletteFromBitmap( LPDIRECTDRAWPALETTE* ppPalette, const TCHAR* strBMP );
HRESULT ChangeBackBufferSize(int width,int height); //add by ajohn 修改后台缓冲区的大小~
// Display methods
HRESULT Clear( DWORD dwColor = 0L );
HRESULT ColorKeyBlt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
RECT* prc = NULL );
HRESULT Blt( DWORD x, DWORD y, LPDIRECTDRAWSURFACE7 pdds,
RECT* prc=NULL, DWORD dwFlags=0 );
HRESULT Blt( DWORD x, DWORD y, CSurface* pSurface, RECT* prc = NULL );
//add by ajohn 自动选取rt进行帖图
HRESULT Blt( int x,int y,CSurface* pSurface);
//add by ajohn 内存到显存的blt
HRESULT Qmemcpy(DWORD x,DWORD y,CSurface* pSurface,RECT* prc, int nQWORDs);
//add by ajohn 加亮,减暗的Blt
HRESULT ShadleBlt(DWORD x,DWORD y,CSurface* pSurface,RECT* prc,int shadle);
//add by ajohn 带alpha的混合blt
HRESULT AlphaBlt(int x,int y,CSurface* pSurface,BYTE alpha,DWORD KeyColor);
//add by ajohn 带alpha的混合blt
HRESULT AlphaBlt(DWORD x,DWORD y,CSurface* pSurface,RECT* prc,BYTE alpha,DWORD KeyColor);
HRESULT ShowBitmap( HBITMAP hbm, LPDIRECTDRAWPALETTE pPalette=NULL );
HRESULT SetPalette( LPDIRECTDRAWPALETTE pPalette );
HRESULT Present();
};
//-----------------------------------------------------------------------------
// Name: class CSurface
// Desc: Class to handle aspects of a DirectDrawSurface.
//-----------------------------------------------------------------------------
class CSurface
{
LPDIRECTDRAWSURFACE7 m_pdds;
DDSURFACEDESC2 m_ddsd;
BOOL m_bColorKeyed;
public:
LPDIRECTDRAWSURFACE7 GetDDrawSurface() { return m_pdds; }
DDSURFACEDESC2 GetDDrawDesc() { return m_ddsd;}
BOOL IsColorKeyed() { return m_bColorKeyed; }
//add by ajohn
// HRESULT DDLoadBitmap(LPDIRECTDRAW7 pdd, LPCSTR szBitmap, int dx, int dy);
// HRESULT DDCopyBitmap(LPDIRECTDRAWSURFACE7 pdds, HBITMAP hbm, int x, int y, int dx, int dy);
HRESULT DrawBitmap(HBITMAP hBMP, DWORD dwBMPOriginX = 0, DWORD dwBMPOriginY = 0,
DWORD dwBMPWidth = 0, DWORD dwBMPHeight = 0 );
HRESULT DrawBitmap( TCHAR* strBMP, DWORD dwDesiredWidth, DWORD dwDesiredHeight );
HRESULT DrawText( HFONT hFont, TCHAR* strText, DWORD dwOriginX, DWORD dwOriginY,
COLORREF crBackground, COLORREF crForeground );
HRESULT SetColorKey( DWORD dwColorKey );
DWORD ConvertGDIColor( COLORREF dwGDIColor );
static HRESULT GetBitMaskInfo( DWORD dwBitMask, DWORD* pdwShift, DWORD* pdwBits );
HRESULT Create( LPDIRECTDRAW7 pDD, DDSURFACEDESC2* pddsd );
HRESULT Create( LPDIRECTDRAWSURFACE7 pdds );
HRESULT Destroy();
CSurface();
~CSurface();
};
#endif // DDUTIL_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -