|

楼主 |
发表于 2004-7-20 21:48:00
|
显示全部楼层
Re:DirectDraw 初级问题
BOOL CMainFrame: rawInitial()
{//初始化DirectDraw
//**Initialize the OLE/COM library
if(FAILED(CoInitialize(NULL)))
{
Msg("OLE/COM library initial failed err");
return false;
}
//create a direct draw object and interface
HRESULT result=CoCreateInstance(CLSID_DirectDraw,NULL,CLSCTX_ALL,
IID_IDirectDraw7,(void**)&m_pIDraw);
//CoCreateInstance返回一个指向新的DirectDraw对象的IDirectDraw7接口的指针
if(result!=DD_OK)
{
Msg("CoCreateInstance failed err=%d",result);
return FALSE;
}
result=m_pIDraw->Initialize((GUID*)NULL);
if(result!=DD_OK)
{
Msg("DDraw initail failed err=%d",result);
return FALSE;
}
result=m_pIDraw->SetCooperativeLevel(m_hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN|DDSCL_ALLOWREBOOT);
if(result!=DD_OK)
{
Msg("SetCooperativeLevel failed err=%d",result);
return FALSE;
}
result = m_pIDraw->SetDisplayMode(640,480,8,0,0);//设定屏幕显示模式
if(result!=DD_OK)
{
Msg("SetDisplayMode failed err=%d",result);
return FALSE;
}
//check capabilites
DDCAPS ddcaps;
ddcaps.dwSize=sizeof(DDCAPS);
result=m_pIDraw->GetCaps(&ddcaps,NULL);
if(result!=DD_OK)
{
Msg("GetCaps failed err=%d",result);
return FALSE;
}
if(ddcaps.dwCaps&DDCAPS_NOHARDWARE)
{
Msg("No hardware support at all");
}
DDSURFACEDESC2 ddsd;
::ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(DDSURFACEDESC2);
ddsd.dwFlags=DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount=1; //简单换页链
result=m_pIDraw->CreateSurface(&ddsd,&m_pIMainSurface,NULL); //前台主页面
if(result!=DD_OK)
{
Msg("Create MainSurface failed err=%d",result);
return FALSE;
}
DDSCAPS2 ddscaps;
::ZeroMemory(&ddscaps,sizeof(DDSCAPS2));
ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
result=m_pIMainSurface->GetAttachedSurface(&ddscaps,&m_pIFlipSurface); //后台缓冲
if(result!=DD_OK)
{
Msg("GetAttachedsurface failed err=%d",result);
return FALSE;
}
//create memorySurface to load bitmap
//should be in Physical Mem not in VM
::ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(ddsd);
ddsd.dwFlags=DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH;
ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth=256;
ddsd.dwHeight=256;//图片的大小
result=m_pIDraw->CreateSurface(&ddsd,&m_pIMemorySurface,NULL); //后备页面
if(result!=DD_OK)
{
Msg("Create MemorySurface failed err=%d",result);
return FALSE;
}
return TRUE;
} |
|