www.pudn.com > Chesssource.rar > winmain.cpp


#include "stdafx.h" 
 
BOOL InitWindow( HINSTANCE hInstance, int nCmdShow ); 
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam );  
 
HWND hWnd; 
#define WIDTH 640 
#define HEIGHT 480 
 
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) 
{ 
	if(!InitWindow(hInstance, nCmdShow)) return FALSE; 
	MSG msg; 
 
	cChess chess; 
	if(chess.Init(hWnd,hInstance)) 
	{ 
		for(;;) 
		{ 
			if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
			{ 
				if(msg.message == WM_QUIT) break; 
				TranslateMessage(&msg); 
				DispatchMessage(&msg); 
			} 
			else 
			{ 
				if(chess.Frame() == FALSE) 
					break; 
			} 
		} 
	} 
 
	CoUninitialize(); 
	UnregisterClass("Chess", hInstance); 
 
	return (int)(msg.wParam); 
} 
 
static BOOL InitWindow(HINSTANCE hInstance, int nCmdShow ) 
{ 
	WNDCLASSEX wcex; 
	wcex.cbSize        = sizeof(WNDCLASSEX); 
	wcex.style         = CS_CLASSDC; 
	wcex.lpfnWndProc   = (WNDPROC)WinProc; 
	wcex.cbClsExtra    = 0; 
	wcex.cbWndExtra    = 0; 
	wcex.hInstance     = hInstance; 
	wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION); 
	wcex.hCursor       = LoadCursor(NULL, IDC_ARROW); 
	wcex.hbrBackground = NULL; 
	wcex.lpszMenuName  = NULL; 
	wcex.lpszClassName = "Chess"; 
	wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION); 
 
	if(!RegisterClassEx(&wcex))  
		return FALSE; 
 
	hWnd = CreateWindow("Chess", "Chess Demo", WS_BORDER|WS_CAPTION|WS_MINIMIZEBOX|WS_SYSMENU,  
		(GetSystemMetrics(SM_CXSCREEN)-WIDTH)/2, (GetSystemMetrics(SM_CYSCREEN)-HEIGHT)/2, 
		WIDTH, HEIGHT, NULL, NULL, hInstance, NULL); 
	if(!hWnd) return FALSE; 
 
	ShowWindow(hWnd, SW_NORMAL); 
	UpdateWindow(hWnd); 
 
	CoInitialize(NULL); 
 
	return TRUE; 
} 
 
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) 
{ 
	switch(message) 
	{ 
	case WM_DESTROY: 
		PostQuitMessage(0); 
		return 0; 
	} 
 
	return DefWindowProc(hWnd, message, wParam, lParam); 
}