首页 > 代码库 > DirectDraw 直接显示RGB图象的最简单实现

DirectDraw 直接显示RGB图象的最简单实现

 
来自:
 

#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(); 


BOOL CDDraw::Init(HWND hWnd,int nWidth,int nHeight) 

if(hWnd==NULL) return FALSE; 

m_hDrawWnd=hWnd; 

if(DirectDrawCreate(NULL,&lpDD,NULL)!=DD_OK)return FALSE; 

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 FALSE; 

if(lpDD->CreateClipper(NULL,&lpClipperBack,NULL)!=DD_OK) return FALSE; 

lpClipperBack->SetHWnd(0,hWnd); 

lpDDSPrimary->SetClipper(lpClipperBack); 

lpClipperBack->Release(); 
lpClipperBack=NULL; 

ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; 
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; 
ddsd.dwHeight = nHeight; 
ddsd.dwWidth = nWidth; 
if(lpDD->CreateSurface(&ddsd, &lpBackdds, NULL)!=DD_OK) return FALSE; 

return 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, 
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); 


void CDDraw::CleanUp() 
{
if(lpDD!=NULL) 

if(lpClipperBack!=NULL) 

lpClipperBack->Release(); 
lpClipperBack=NULL; 


if(lpDDSPrimary!=NULL) 

lpDDSPrimary->Release(); 
lpDDSPrimary=NULL; 


if(lpBackdds!=NULL) 

lpBackdds->Release(); 
lpBackdds=NULL; 


lpDD->Release(); 
lpDD=NULL; 

} (ixmy)
 
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200903/7227.html]
<iframe height="15" marginHeight="0" src="http://pos.baidu.com/ecom?cec=GBK&dai=1&cfv=11&cpa=1&col=zh-CN&dis=0&xuanting=0&n=28032004_cpr&conOP=0&scale=&skin=&rsi0=468&rsi1=15&rsi5=4&ltr=http%3A%2F%2Fwww.rosoo.net%2Fa%2Flist_45_33.html&ltu=http%3A%2F%2Fwww.rosoo.net%2Fa%2F200903%2F7227.html&pcs=1583x746&rss0=%23FFFFFF&rss1=%23FFFFFF&rss2=%230000FF&rss3=&rss4=&rss5=&rss6=%23e10900&rss7=&rad=&pis=10000x10000&aurl=&psr=1600x900&pss=1583x3798&tpr=1398856304423&lunum=6&ch=0&at=103&qn=96dfdab6359ec5c4&ps=3790x311&tn=tlink_default_468_15&ts=1&c01=0&td_id=936497&adn=0&cad=1&ccd=32&dtm=BAIDU_DUP2_SETJSONADSLOT&dc=2&di=u936497" frameBorder="0" width="468" marginWidth="0" scrolling="no" align="center,center"></iframe>