After you create an application window, you can begin initializing the primary DirectX objects whose services you will draw on to render the scene. For a Direct3D application, this means creating and configuring DirectDraw, rendering surfaces, a rendering device, and a viewport. For clarity, the Triangle sample separates system object initialization code from the code for initializing the scene. As a result, geometry, application-specific data structures, and lesser Direct3D objects like materials are initialized with the scene. This isn't a requirement, but it makes for simpler code.
The Triangle sample performs system initialization in the Initialize3DEnvironment application-defined function, called from WinMain after the window is created. Although preparing these objects isn't complex, the code is a little too lengthy to discuss in one place. As a result, the steps taken by the Initialize3DEnvironment function are presented in the following substeps:
Note The Triangle sample code performs initialization by calling methods from within the WinMain function, immediately after the application window is created, rather than in response to system creation messages such as WM_CREATE. It does this to avoid relying on system message ordering, which can differ across platforms.