Example #1
0
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	LPCWSTR		className = L"BrickBreak";
	HWND		hWnd;
	WNDCLASSEX	wncx;

	ZeroMemory(&wncx, sizeof(WNDCLASSEX));
	wncx.cbSize = sizeof(WNDCLASSEX);
	wncx.hInstance = hInstance;
	wncx.lpszClassName = className;
	wncx.style = CS_HREDRAW | CS_VREDRAW;
	wncx.lpfnWndProc = WindowProc;
	wncx.cbClsExtra = 0;
	wncx.cbWndExtra = 0;

	RegisterClassEx(&wncx);

	hWnd = CreateWindowEx(0, className, L"Brick Break", WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, NULL, hInstance, NULL);

	if (hWnd == NULL)
	{
		MessageBox(hWnd, L"'CreateWindowEx' Failed", L"Win32 Error", MB_OK);
		return 0;
	}

	bool		loaded	= false;
	Graphics	*gfx	= new Graphics(hWnd);
	BrickBreak	*game	= new BrickBreak();
	gfx->AddBatch(game);

	loaded = game->LoadResources(gfx->pDevice);
	game->Start();

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	MSG msg;
	while (true)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if (msg.message == WM_QUIT)
			break;

		if (!loaded)
			loaded = game->LoadResources(gfx->pDevice);

		game->Update();
		gfx->Render();
	}

	SafeDelete(game);
	SafeDelete(gfx);

	UnregisterClass(className, hInstance);

	return (int) msg.wParam;
}