Is it possible, somehow to avoid the single frame of black that appears before a DirectX9 window is displayed in fullscreen? My code looks like this.

WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, L"D3D", NULL };
RegisterClassEx( &wc );
LPDIRECT3D9         pD3D = NULL;   
LPDIRECT3DDEVICE9   pd3dDevice = NULL;  
int                 windowWidth = 1280;  
int                 windowHeight = 1024;  
int                 adapter = 3;  
bool                fullscreen = true;      

if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
    return E_FAIL;

HWND hWnd = CreateWindow( L"D3D", L"D3D Test", WS_VISIBLE | WS_POPUP, 0, 0, windowWidth, windowHeight, NULL, NULL, wc.hInstance, NULL );

pD3D->GetAdapterDisplayMode( adapter, &d3ddm );

ZeroMemory( &d3dpp, sizeof(d3dpp) );

d3dpp.Windowed               = !fullscreen;
d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat       = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_ONE;
d3dpp.BackBufferCount        = 1;
d3dpp.BackBufferWidth        = windowWidth;
d3dpp.BackBufferHeight       = windowHeight;
d3dpp.hDeviceWindow          = hWnd;

if( FAILED( pD3D->CreateDevice( adapter, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice ) ) )
    return E_FAIL;

MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message != WM_QUIT )
    pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 255, 255, 255 ), 1.0f, 0 );
    pd3dDevice->Present( NULL, NULL, NULL, NULL );

    if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        TranslateMessage( &msg );
        DispatchMessage( &msg );

if( pd3dDevice != NULL )

if( pd3dDevice != NULL )

UnregisterClass( L"D3D", wc.hInstance );
return 0;


  • \$\begingroup\$ try removing the present call in your message pump. \$\endgroup\$
    – Tordin
    Jan 10, 2013 at 16:48
  • \$\begingroup\$ You need to put your pd3dDevice->* calls into an else connected with if( PeekMessage(...) ), otherwise your app will appear to be unresponsive if there is more than one WM_MESSAGE in the queue \$\endgroup\$
    – bobobobo
    Jan 10, 2013 at 19:34
  • \$\begingroup\$ Don't use L in front of unicode strings use the TEXT macro instead. L"D3D" should become TEXT("D3D"). \$\endgroup\$
    – bobobobo
    Jan 10, 2013 at 19:35

1 Answer 1


If you're referring to the fact that the screen may go black for a second or two during a switch to fullscreen[*] and before the scene is actually displayed following the switch, then you will very likely not be able to remove it. Changing to a fullscreen mode may involve a video mode change for your display device, and if this needs to happen then the black frame is just part of the normal video mode change process - you'll see the same if you e.g. change the screen resolution using your display control panel (which this is effectively identical to).

It's possible to sometimes avoid the need for this to happen if the fullscreen mode you're using is identical in all respects to the current display mode, but there's another catch - with Vista or higher a switch to fullscreen will also disable the DWM, which also causes a frame of black.

So this isn't a problem with your code and there's nothing you can do in code to avoid it - it's a property of your OS and display driver.

There is however one workaround, and that's to not use a fullscreen mode. Instead create a windowed mode at your desktop resolution, but use no title bar/borders/etc on the window. Of course that will run a little slower compared to a true fullscreen mode, but it may not matter if you're already running fast enough.

[*] - when I say "switch to fullscreen" you may assume that I also mean "starting in a fullscreen mode" here.

  • \$\begingroup\$ Thanks, I feared this was the case. It's Windows 7 so I will try disabling Aero and see if that helps. Unfortunately, it "has to be fullscreen" otherwise the borderless window solution would be perfect. \$\endgroup\$ Jan 11, 2013 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .