/* Chapters 4, 5 (projections) and 15 have this in a KillWindow
	   function that is called at the end of WinMain.  Good idea?
	   Could also be called in Window::close

	   if (hRC_)
	  {
		// release the RC
		if (!wglMakeCurrent(NULL,NULL))
		{
		  MessageBox(NULL, "Unable to release rendering context", "Error", MB_OK | MB_ICONINFORMATION);
		}

		// delete the RC
		if (!wglDeleteContext(hRC_))
		{
		  MessageBox(NULL, "Unable to delete rendering context", "Error", MB_OK | MB_ICONINFORMATION);
		}

		hRC_ = NULL;
	  }

	  // release the DC if we have one
	  if (hDC_ && !ReleaseDC(g_hwnd, hDC_))
	  {
		MessageBox(NULL, "Unable to release device context", "Error", MB_OK | MB_ICONINFORMATION);
		hDC_ = NULL;
	  }

	  // destroy the window if we have a valid handle
	  if (g_hwnd && !DestroyWindow(g_hwnd))
	  {
		MessageBox(NULL, "Unable to destroy window", "Error", MB_OK | MB_ICONINFORMATION);
		g_hwnd = NULL;
	  }

	  // unregister our class so we can create a new one if we need to
	  if (!UnregisterClass(WND_CLASS_NAME, g_hInstance))
	  {
		MessageBox(NULL, "Unable to unregister window class", "Error", MB_OK | MB_ICONINFORMATION);
		g_hInstance = NULL;
	  }

	  */
	HWND Window::initialize (HINSTANCE hInst, 
			int w, 
			int h, 
			int x, int y, //top left corner
			int b, 
			bool fscreen,
			bool StencilBufferEnabled)
	{
		RECT windowRect;
		DWORD	   dwExStyle;						// Window Extended Style
		DWORD	   dwStyle;						// Window Style

		isFullScreen_ = fscreen;
		width_		  = w;
		height_		  = h;
		bits_		  = b;
		hInstance_	  = hInst;

		Register (hInst); 

		windowRect.left=  (long)x;						// Set Left Value To 0
		windowRect.right= (long)(width()+x);						// Set Right Value To Requested Width
		windowRect.top=   (long)y;							// Set Top Value To 0
		windowRect.bottom=(long)(height()+y);						// Set Bottom Value To Requested Height

		if (isFullScreen_)
		{
			dwExStyle = WS_EX_APPWINDOW;
			dwStyle = WS_POPUP;
		}
		else
		{
			dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
			dwStyle = WS_OVERLAPPEDWINDOW;
		}

		AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
	
		// create the window
		if (isFullScreen_)
		{
			beginFullScreen(); 
			hWND_ = CreateWindowEx(NULL, "Engine", name_.c_str(), dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
							  0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
							  NULL, NULL, (HINSTANCE)GetModuleHandle(NULL), (void*)this);
		}
		else
		{

			hWND_ = CreateWindowEx(NULL, "Engine", name_.c_str(), dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
							  0, 0, width (), height (), NULL, NULL, (HINSTANCE)GetModuleHandle(NULL),(void*)this);
		}

		// check if window creation failed (hwnd would equal NULL)
		if (!hWND_)
			throw CantInitialize ();

		createContexts (hWND_, StencilBufferEnabled);

		ShowWindow(hWND_, SW_SHOW);			// display the window
		UpdateWindow(hWND_);					// update the window

		SetForegroundWindow(hWND_);
		SetCapture(hWND_);
		SetFocus(hWND_);

		ShowCursor(FALSE);

		return hWND_;
	}
void MakeCurrentPerfCase::init (void)
{
	chooseConfig();
	createContexts();
	createSurfaces();
}