Repainting the Client Area

The OnPaint function repaints the client area, when required. Notice that it calls the DoFrame function to do much of the work, even though DoFrame re-renders the scene as well as blitting the result to the primary surface. Although the re-rendering is not necessary, for this simple sample this inefficiency does not matter. In your application, you should re-render only when the scene changes.

For more information about the DoFrame function, see Rendering a Single Frame.

static LRESULT

OnPaint(HWND hwnd, HDC hdc, LPPAINTSTRUCT lpps)

{

HRESULT hRes;

USE_PARAM(lpps);

if (fActive && !fSuspended && (NULL != lpd3dDevice))

{

hRes = DoFrame();

if (FAILED(hRes))

{

FatalError(hwnd, IDS_ERRMSG_RENDERSCENE, hRes);

return 0L;

}

}

else

{

// Show the suspended image if we are not active or suspended or

// if we have not yet created the device.

PaintSuspended(hwnd, hdc);

}

return 0L;

}