WinMain Function

int PASCAL

WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpszCommandLine,

int cmdShow)

{

WNDCLASS wndClass;

HWND hwnd;

MSG msg;

USE_PARAM(hPrevInstance);

// Record the instance handle.

hAppInstance = hInstance;

// Very simple command-line processing. We only have one

// option - debug - so we will just assume that if anything was

// specified on the command line the user wants debug mode.

// (In debug mode there is no hardware and all surfaces are

// explicitly in system memory.)

if (0 != *lpszCommandLine)

fDebug = TRUE;

// Register the window class.

wndClass.style = 0;

wndClass.lpfnWndProc = WndProc;

wndClass.cbClsExtra = 0;

wndClass.cbWndExtra = 0;

wndClass.hInstance = hInstance;

wndClass.hIcon = LoadIcon(hAppInstance,

MAKEINTRESOURCE(IDI_APPICON));

wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);

wndClass.hbrBackground = GetStockObject(WHITE_BRUSH);

wndClass.lpszMenuName = NULL;

wndClass.lpszClassName = WINDOW_CLASSNAME;

RegisterClass(&wndClass);

// Create the main window of the instance.

hwnd = CreateWindow(WINDOW_CLASSNAME,

WINDOW_TITLE,

WS_OVERLAPPED | WS_SYSMENU,

CW_USEDEFAULT, CW_USEDEFAULT,

WINDOW_WIDTH, WINDOW_HEIGHT,

NULL,

NULL,

hInstance,

NULL);

ShowWindow(hwnd, cmdShow);

UpdateWindow(hwnd);

// The main message dispatch loop.

// NOTE: For simplicity we handle the message loop with a

// simple PeekMessage scheme. This might not be the best

// mechanism for a real application (a separate render worker

// thread might be better).

while (TRUE)

{

if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))

{

// Message pending. If it's QUIT then exit the message

// loop. Otherwise, process the message.

if (WM_QUIT == msg.message)

{

break;

}

else

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

else

{

// Animate the scene.

OnIdle(hwnd);

}

}

return msg.wParam;

}