directdraw初始化失败
发布网友
发布时间:2022-04-29 20:48
我来回答
共2个回答
热心网友
时间:2023-10-09 00:40
最简单的是使用全屏独占模式。
要开始初始化dd,首先创建并显示一个窗口,获得它的句柄;
初始化代码:
#include
#pragma
comment(lib,"dxguid.lib")
#pragma
comment(lib,"ddraw.lib")
lpdirectdraw7
lpdd;
lpdirectdrawsurface7
lpddsmain;
lpdirectdrawsurface7
lpddsback;
//下面程序初始化dd,并设置窗口分辨率为width*height,bpp为色深,注意要设定相应变量的值为适合的值(如800*600*16),否则初始化失败。
bool
initddraw(hwnd
hwnd,
int
width,
int
height,
int
bpp)
{
if(failed(directdrawcreateex(null,
(void**)&lpdd,
iid_idirectdraw7,
null)))
return
false;
if(failed(lpdd->setcooperativelevel(hwnd,
ddscl_exclusive|ddscl_fullscreen)))
return
false;
if(failed(lpdd->setdisplaymode(width,
height,
bpp,
0,
0)))
return
false;
ddsurfacedesc2
ddsd;
zeromemory(
&ddsd,
sizeof(
ddsd
)
);
ddsd.dwsize
=
sizeof(
ddsd
);
ddsd.dwflags
=
ddsd_caps
|
ddsd_backbuffercount;
ddsd.ddscaps.dwcaps
=
ddscaps_primarysurface
|
ddscaps_flip
|
ddscaps_complex
|
ddscaps_3ddevice;
ddsd.dwbackbuffercount
=
1;
if(failed(lpdd->createsurface(
&ddsd,
&lpddsmain,
null)))
return
false;
//
get
a
pointer
to
the
back
buffer
ddscaps2
ddscaps;
zeromemory(
&ddscaps,
sizeof(
ddscaps
)
);
ddscaps.dwcaps
=
ddscaps_backbuffer;
if(failed(lpddsmain->getattachedsurface(
&ddscaps,
&lpddsback)))
return
false;
lpddsback->addref();
return
true;
}
热心网友
时间:2023-10-09 00:41
1、重装游戏;
2、重装DIRECT X;
3、重新显卡驱动;