Example #1
0
//-------------------------------- WinMain -------------------------------
//
//	The entry point of the windows program
//------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPSTR     szCmdLine, 
					int       iCmdShow)
{
	//handle to our window
	HWND						hWnd;

	//our window class structure
	WNDCLASSEX     winclass;

	// first fill in the window class stucture
	winclass.cbSize        = sizeof(WNDCLASSEX);
	winclass.style         = CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc   = WindowProc;
	winclass.cbClsExtra    = 0;
	winclass.cbWndExtra    = 0;
	winclass.hInstance     = hInstance;
	winclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	winclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	winclass.hbrBackground = NULL;
	winclass.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
	winclass.lpszClassName = g_szWindowClassName;
	winclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

	//register the window class
	if (!RegisterClassEx(&winclass))
	{
		MessageBox(NULL, "Registration Failed!", "Error", 0);

		//exit the application
		return 0;
	}

	//create the window and assign its ID to hwnd    
	hWnd = CreateWindowEx (NULL,                 // extended style
		g_szWindowClassName,  // window class name
		g_szApplicationName,  // window caption
		WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
		GetSystemMetrics(SM_CXSCREEN)/2 - constWindowWidth/2,
		GetSystemMetrics(SM_CYSCREEN)/2 - constWindowHeight/2,                    
		constWindowWidth,     // initial x size
		constWindowHeight,    // initial y size
		NULL,                 // parent window handle
		NULL,                 // window menu handle
		hInstance,            // program instance handle
		NULL);                // creation parameters

	//make sure the window creation has gone OK
	if(!hWnd)
	{
		MessageBox(NULL, "CreateWindowEx Failed!", "Error!", 0);
	}


	//make the window visible
	ShowWindow (hWnd, iCmdShow);
	UpdateWindow (hWnd);

	// Enter the message loop
	bool bDone = false;

	//create a timer
	PrecisionTimer timer;

	timer.SmoothUpdatesOn();

	//start the timer
	timer.Start();

	MSG msg;

	while(!bDone)
	{		
		while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
		{
			if( msg.message == WM_QUIT) 
			{
				//stop loop if it's a quit message
				bDone = true;
			} 

			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
		}

		if (msg.message != WM_QUIT )
		{
			//update
			g_GameWorld->Update(timer.TimeElapsed());

			//render
			RedrawWindow(hWnd, false);

			Sleep(2);
		}

	}//end while




	delete g_GameWorld;

	UnregisterClass( g_szWindowClassName, winclass.hInstance );

	return msg.wParam;
}