The WinMain function in Helworld.c has only a few lines of code that are unique to an application that uses DirectDraw and Direct3D's Retained Mode. The InitApp and CleanUp functions are standard parts of a Windows program, although in the case of Helworld, they perform some unique tasks. The most important call in WinMain, from the perspective of Direct3D, is the call to the RenderLoop function. RenderLoop is responsible for drawing each new frame of the animation. For more information about the RenderLoop function, see The Rendering Loop.
/////////////////////////////////////////////////////////////////////
//
// WinMain
// Initializes the application and enters a message loop.
// The message loop renders the scene until a quit message is received.
//
/////////////////////////////////////////////////////////////////////
int PASCAL
WinMain (HINSTANCE this_inst, HINSTANCE prev_inst, LPSTR cmdline,
int cmdshow)
{
MSG msg;
HACCEL accel = NULL;
int failcount = 0; // Number of times RenderLoop has failed
prev_inst;
cmdline;
// Create the window and initialize all objects needed to begin
// rendering.
if (!InitApp(this_inst, cmdshow))
return 1;
while (!myglobs.bQuit) {
// Monitor the message queue until there are no pressing
// messages.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (!TranslateAccelerator(msg.hwnd, accel, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// If the app is not minimized, not about to quit, and D3DRM has
// been initialized, begin rendering.
if (!myglobs.bMinimized && !myglobs.bQuit &&
myglobs.bInitialized) {
// Attempt to render a frame. If rendering fails more than
// twice, abort execution.
if (!RenderLoop())
++failcount;
if (failcount > 2) {
CleanUp();
break;
}
}
}
return msg.wParam;
}