#include "Game.h"
#include "cGameAppWin.h"
#include "resource.h"

cGameAppWin::cGameAppWin(){

}

cGameAppWin::~cGameAppWin(){

}

BOOL cGameAppWin::RegisterClass(){
	return cWindow::RegisterClass(
		"GameAppWin", 
		CS_HREDRAW | CS_VREDRAW, 
		LoadIcon(*GetGameApp(), MAKEINTRESOURCE(IDR_GAMEAPP)),
		LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)),
		(HBRUSH)GetStockObject(BLACK_BRUSH));
}

//////////////////////////////////////////////////////////////////////
// Window Prodedure
//////////////////////////////////////////////////////////////////////

LRESULT cGameAppWin::Proc(UINT uMsg, WPARAM wParam, LPARAM lParam){
	switch(uMsg){
	case WM_CREATE:
		if(!OnCreate(wParam, lParam))
			return -1;
		return 0;
	case WM_DESTROY:
		OnDestroy(wParam, lParam);
		return 0;
	case WM_CLOSE:
		PostQuitMessage(0);
		return 0;
	case WM_SETFOCUS:
		if(pChild) pChild->SetFocus();
		return 0;
	}
	return DefProc(uMsg, wParam, lParam);
}


BOOL cGameAppWin::OnCreate(WPARAM wParam, LPARAM lParam){
	// 다이렉트 드로우를 초기화 한다.
	cDisplay *pDisp = GetDisplay();

	if(!pDisp->Create(hWnd)) return FALSE;
	if(!pDisp->SetCooperativeLevel(DDSCL_NORMAL)) return FALSE;
	if(!pDisp->CreateDoubleBuffer()) return FALSE;

	pChild = 0;
	return TRUE;
}

void cGameAppWin::OnDestroy(WPARAM wParam, LPARAM lParam){
	// 다이렉트 드로우를 제거한다.
	cDisplay *pDisp = GetDisplay();

	pDisp->DestroyDoubleBuffer();
	pDisp->Destroy();
}
