帮忙看一段DirectDraw代码

qtgm 2004-12-24 11:12:56
#include <afxwin.h>
#include <ddraw.h>

class MFrame:public CFrameWnd{
public:
LPDIRECTDRAW7 lpd;
LPDIRECTDRAWSURFACE7 lpzz;
LPDIRECTDRAWSURFACE7 lpbb;
LPDIRECTDRAWSURFACE7 lpma;
LPDIRECTDRAWSURFACE7 lpmb;
LPDIRECTDRAWSURFACE7 lpmc;
LPDIRECTDRAWSURFACE7 lpmd;
LPDIRECTDRAWSURFACE7 lpme;
LPDIRECTDRAWSURFACE7 lpmf;
LPDIRECTDRAWSURFACE7 lpmmu;
LPDIRECTDRAWSURFACE7 lpmmd;
DDSCAPS2 caps;
DDSURFACEDESC2 desc;
HRESULT result;
HDC hdc,hdc1;
DDCOLORKEY key;
HBITMAP ssgg,plmm,dl,mm1,mm2,mm3;

MFrame()
{
Create(0,"MFC",WS_POPUP);
CreateDraw();
LoadPic();
}
~MFrame()
{
lpd->Release();
lpzz->Release();
lpma->Release();
lpmb->Release();
lpmc->Release();
lpmd->Release();
lpme->Release();
lpmf->Release();
}
void CreateDraw()
{
int result = DirectDrawCreateEx(NULL,(VOID**)&lpd,IID_IDirectDraw7,NULL);
if(result != DD_OK) return ;
result = lpd->SetCooperativeLevel(m_hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN|DDSCL_ALLOWREBOOT);
result = lpd->SetDisplayMode(640,480,32,0,DDSDM_STANDARDVGAMODE);
memset(&desc,0,sizeof(desc));
desc.dwSize = sizeof(desc);
desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
desc.dwBackBufferCount = 1;
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
result = lpd->CreateSurface(&desc,&lpzz,NULL);
caps.dwCaps = DDSCAPS_BACKBUFFER;
result = lpzz->GetAttachedSurface(&caps,&lpbb);
memset(&desc,0,sizeof(desc));
desc.dwSize = sizeof(desc);
desc.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN ;
desc.dwWidth = 640;
desc.dwHeight = 480;
result = lpd->CreateSurface(&desc, &lpma, NULL);
result = lpd->CreateSurface(&desc, &lpmb, NULL);
result = lpd->CreateSurface(&desc, &lpmc, NULL);
result = lpd->CreateSurface(&desc, &lpmd, NULL);
result = lpd->CreateSurface(&desc, &lpme, NULL);
result = lpd->CreateSurface(&desc, &lpmf, NULL);
result = lpd->CreateSurface(&desc, &lpmmu, NULL);
result = lpd->CreateSurface(&desc, &lpmmd, NULL);
/**/
}

void LoadPic()
{
hdc = ::CreateCompatibleDC(NULL);
ssgg = (HBITMAP)::LoadImage(NULL,"p.bmp",IMAGE_BITMAP,40,40,LR_LOADFROMFILE);
plmm = (HBITMAP)::LoadImage(NULL,"plmm.bmp",IMAGE_BITMAP,40,40,LR_LOADFROMFILE);
dl = (HBITMAP)::LoadImage(NULL,"dl.bmp",IMAGE_BITMAP,40,40,LR_LOADFROMFILE);

::SelectObject(hdc,ssgg);
lpma->GetDC(&hdc1);
::BitBlt(hdc1,0,0,40,40,hdc,0,0,SRCCOPY);
lpma->ReleaseDC(hdc1);
key.dwColorSpaceHighValue=255;
lpma->SetColorKey(DDCKEY_SRCBLT,&key);
}

void DrawPic()
{
lpbb->BltFast(0,0,lpma,CRect(0,0,40,40),DDBLTFAST_WAIT);
lpzz->Flip(NULL,DDFLIP_WAIT);
}

void OnPaint()
{

CPaintDC d(this);
DrawPic();

}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(MFrame,CFrameWnd)
ON_WM_TIMER()
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_KEYUP()
ON_WM_KEYDOWN()
END_MESSAGE_MAP()
class MWin:public CWinApp{

public:
BOOL InitInstance()
{
MFrame *mframe;
mframe = new MFrame;
mframe->ShowWindow(3);
m_pMainWnd = mframe;
return TRUE;
}
};
MWin mwin;

把DrawPic里面的lpbb->BltFast(0,0,lpma,CRect(0,0,40,40),DDBLTFAST_WAIT);注释掉
就是黑屏了
不注释掉运行的时候会退出

真郁闷,不知道是什么原因
...全文
68 点赞 收藏 2
写回复
2 条回复
myling 2004年12月27日
在所有的页面创建后检查result
看是否页面创建有问题
回复 点赞
天堂里的死神 2004年12月25日
HRESULT BltFast( DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwTrans );
按照原型来看,在第四个参数那里传的是一个CRect(0,0,40,40)对象,而希望接受的其实是一个指向Rect的指针,会不会是这个原因?

其他的,可以试试看检查一下返回值,看返回值是下面的哪一个也好对症下药。
DDERR_INVALIDPARAMS One or more of the input parameters is invalid.
DDERR_SURFACELOST Access to this surface is being refused because the surface memory is gone. The DirectDrawSurface object representing this surface should have Restore called on it.
DDERR_SURFACEBUSY Access to this surface is being refused because the surface is already locked by another thread.
DDERR_INVALIDOBJECT DirectDraw received a pointer that was an invalid DirectDraw object.
DDERR_INVALIDRECT Rectangle provided was invalid.
DDERR_EXCEPTION An exception was encountered while performing the requested operation.
DDERR_UNSUPPORTED Action not supported.
DDERR_GENERIC Generic failure.
DDERR_NOBLTHW No blitter hardware present.

回复 点赞
发动态
发帖子
游戏开发
创建于2007-08-27

7265

社区成员

2.3w+

社区内容

游戏开发相关内容讨论专区
社区公告
暂无公告