|
楼主 |
发表于 2003-9-21 13:30:00
|
显示全部楼层
GameClasses.cpp
#include <ddraw.h>
#include "GameClasses.h"
//------------------CMainControl-------------------
bool CMainControl::Create(int StartX,int StartY,LPDIRECTDRAW7 pDD,char* FileName)
{
x=StartX;
y=StartY;
LoadBMP(FileName,pDD);
return true;
}
void CMainControl:estroy()
{
surf->Release();
surf=NULL;
}
void CMainControl::CreateSurface(LPDIRECTDRAW7 DD,long Height,long Width)
{
DDSURFACEDESC2 sd;
ZeroMemory(&sd,sizeof(sd));
sd.dwSize=sizeof(sd);
sd.dwFlags=DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
sd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
sd.dwHeight=Height;
sd.dwWidth=Width;
DD->CreateSurface(&sd,&surf,NULL);
DDCOLORKEY ColorKey;
ColorKey.dwColorSpaceLowValue=0x00;
ColorKey.dwColorSpaceHighValue=0x00;
surf->SetColorKey(DDCKEY_SRCBLT,&ColorKey);
}
bool CMainControl:oadBMP(char* FileName,LPDIRECTDRAW7 DD)
{
BYTE* BMP;
DWORD BmpSize;
DWORD FileLength;
DWORD nBytesRead;
BITMAPINFO* BmpInfo;
BYTE* Pixels;
HDC hdc;
HANDLE hfile=CreateFile(FileName,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
FileLength=GetFileSize(hfile,NULL);
BmpSize=FileLength-sizeof(BITMAPFILEHEADER);
BMP=(BYTE*)malloc(BmpSize);
SetFilePointer(hfile,sizeof(BITMAPFILEHEADER),NULL,FILE_BEGIN);
ReadFile(hfile,(LPVOID)BMP,BmpSize,&nBytesRead,NULL);
CloseHandle(hfile);
BmpInfo=(BITMAPINFO*)BMP;
Pixels=BMP+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256;
CreateSurface(DD,BmpInfo->bmiHeader.biHeight,BmpInfo->bmiHeader.biWidth);
surf->GetDC(&hdc);
StretchDIBits(hdc,0,0,BmpInfo->bmiHeader.biWidth,BmpInfo->bmiHeader.biHeight,0,0,BmpInfo->bmiHeader.biWidth,BmpInfo->bmiHeader.biHeight,Pixels,BmpInfo,0,SRCCOPY);
surf->ReleaseDC(hdc);
free(BMP);
return true;
}
bool CMainControl:aint(LPDIRECTDRAWSURFACE7 PaintSurf)
{
PaintSurf->BltFast(x,y,surf,NULL,DDBLTFAST_SRCCOLORKEY|DDBLTFAST_WAIT);
return true;
} |
|