Setting Up the Device-Creation Callback Function

The third parameter of the D3DAppCreateFromHWND function is an address of a callback function that is implemented as the AfterDeviceCreated function in D3dmain.cpp. AfterDeviceCreated creates the Direct3D viewport and returns it to D3DAppCreateFromHWND.

First the code calls the IDirect3D::CreateViewport method to create a viewport, and then it calls the IDirect3DDevice::AddViewport method to add the viewport to the newly created Direct3D device. After initializing the viewport's dimensions in a D3DVIEWPORT structure, the code calls the IDirect3DViewport::SetViewport method to set the viewport to those dimensions.

Then, the AfterDeviceCreated function calls the InitView function. InitView, like the InitScene function called earlier by D3dmain.cpp, must be implemented by each sample that uses D3dmain.cpp. One implementation of InitView is described in Initializing the Viewport.

After calling InitView and changing some of the menu items, AfterDeviceCreated finishes by calling the CleanUpAndPostQuit function. This function is described in Cleaning Up.