![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicGcq5SMt42b0RXdi1SZwlHdvw1cldWYtl2LcNWa0FGdz9CXt92YuUHZpFmYuUmchh2cvw1LcpDc0RHaiojIsJye.jpg)
來自:
#include "ddraw.h"
class
cddraw
{
public:
void cleanup();
void
drawdib(bitmapinfoheader* pbi,char* pdata,rect*rt);
bool
init(hwnd hwnd,int nwidth,int
nheight);
cddraw();
virtual
~cddraw();
private:
hwnd
m_hdrawwnd;
lpdirectdraw lpdd; // directdraw
對象
lpdirectdrawsurface lpddsprimary; // directdraw
首頁面
lpdirectdrawsurface lpbackdds;
lpdirectdrawclipper
lpclipperback;
};
cddraw::cddraw()
lpdd=null;
lpddsprimary=null;
lpbackdds=null;
lpclipperback=null;
}
cddraw::~cddraw()
if(lpdd!=null)cleanup();
cddraw::init(hwnd hwnd,int nwidth,int
nheight)
if(hwnd==null) return
false;
m_hdrawwnd=hwnd;
if(directdrawcreate(null,&lpdd,null)!=dd_ok)return
lpdd->setcooperativelevel(hwnd,
ddscl_normal);
ddsurfacedesc ddsd;
ddsd.dwsize =
sizeof( ddsd ); //結構的大小
ddsd.dwflags = ddsd_caps;
//指定ddsurfacedesc結構的ddscaps成員為可用
ddsd.ddscaps.dwcaps =
ddscaps_primarysurface; //指定要建立的是首頁面
//建立首頁面對象
if (
lpdd->createsurface( &ddsd, &lpddsprimary, null ) != dd_ok)
return
if(lpdd->createclipper(null,&lpclipperback,null)!=dd_ok)
lpclipperback->sethwnd(0,hwnd);
lpddsprimary->setclipper(lpclipperback);
lpclipperback->release();
ddsd.dwflags
= ddsd_caps | ddsd_height | ddsd_width;
ddscaps_offscreenplain;
ddsd.dwheight =
nheight;
ddsd.dwwidth =
nwidth;
if(lpdd->createsurface(&ddsd, &lpbackdds,
null)!=dd_ok) return false;
true;
void cddraw::drawdib(bitmapinfoheader *pbi,
char *pdata, rect *rt)
rect
srt;
srt.left=0;
srt.top=0;
srt.right=pbi->biwidth;
srt.bottom=pbi->biheight;
hdc
hdc;
lpbackdds->getdc(&hdc);
setdibitstodevice(
hdc,
0,
pbi->biwidth,
// source rectangle width
pbi->biheight, // source rectangle
height
0, // x-coord of source lower-left corner
0, //
y-coord of source lower-left corner
0, // first scan line in
array
pbi->biheight, // number of scan lines
pdata,
// array of dib bits
(const struct tagbitmapinfo*)pbi, // bitmap
information
dib_rgb_colors // rgb or palette
indexes
);
lpbackdds->releasedc(hdc);
lpddsprimary->blt(rt,lpbackdds,&srt,0,null);
cddraw::cleanup()
{
if(lpdd!=null)
if(lpclipperback!=null)
if(lpddsprimary!=null)
lpddsprimary->release();
if(lpbackdds!=null)
lpbackdds->release();
lpdd->release();
}
(ixmy)
本站文章除注明轉載外,均為本站原創或編譯歡迎任何形式的轉載,但請務必注明出處,尊重他人勞動,同學習共成長。轉載請注明:文章轉載自:羅索實驗室 []