来自: |
#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]