1.创建lpOverlaySurface时,设置dwBackBufferCount=1
2.取得lpOverlaySurface的lpBackSurface,代码如下:
//get overlay back surface
DDSCAPS ddscaps;
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_OVERLAY|DDSCAPS_BACKBUFFER;
if(lpOverlaySurface->GetAttachedSurface(&ddscaps, &lpBackSurface) != DD_OK)
return bRet;
3.设置Overlay显示,代码如下:
if(lpOverlaySurface->UpdateOverlay(NULL, lpPrimarySurface, NULL, DDOVER_SHOW, &ovfx) != DD_OK)
return bRet;
如果,设置显示时还没有装载UI,会显示一片黑屏,或者是上次的Overlay残留,所以可以在显示之前(即UpdateOverlay之前),先把lpOverlaySurface填充lpPrimarySurface的内容.代码如下:
lpOverlaySurface->Blt(NULL, lpPrimarySurface, NULL, DDBLT_WAIT, NULL);
4.在lpBackSurface中装载UI,代码如下:
HDC hdc = NULL;
lpBackSurface->GetDC(&hdc);
//在hdc上画你要的东西
...
lpBackSurface->ReleaseDC(hdc);
5.翻转Surface
lpOverlaySurface->Flip(NULL, 0);
为防止在hdc上画东西时,只画了上一画面更新的部分导致的UI错乱,可以在翻转后把lpOverlaySurface画到lpBackSurface上.代码如下:
lpBmpSurface->Blt(NULL, lpOverlaySurface, NULL, DDBLT_WAIT, NULL);
6.lpOverlaySurface在Release之前先要隐藏画面.代码如下:
lpOverlaySurface->UpdateOverlay(NULL, lpPrimarySurface, NULL, DDOVER_HIDE, NULL);