www.pudn.com > HeightMap_D3D.zip > Main.cpp


//----------------------------------------------------------------------------- 
// File: Main.cpp 
// Desc: The Main Program File. "My Second 3D Project". 
// 
// Project Made By: VirgoCI (Costa Itskov) 
// For Comments: virgoci@mail.ru 
//----------------------------------------------------------------------------- 
#include "Main.h" 
 
 
 
 
//----------------------------------------------------------------------------- 
// Global variables 
//----------------------------------------------------------------------------- 
cApp* g_pApp = NULL; 
HWND hWnd; 
 
 
 
 
//----------------------------------------------------------------------------- 
// Name: WinMain() 
// Desc: The application's entry point 
//----------------------------------------------------------------------------- 
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) 
{ 
	WNDCLASSEX WindowClassEx = { 0 }; 
	WindowClassEx.cbSize = sizeof( WNDCLASSEX ); 
	WindowClassEx.style = CS_CLASSDC; 
    WindowClassEx.lpfnWndProc = MsgProc; 
	WindowClassEx.cbClsExtra = 0; 
	WindowClassEx.cbWndExtra = 0; 
    WindowClassEx.hInstance = hInstance; 
	WindowClassEx.hIcon = NULL; 
	WindowClassEx.hCursor = LoadCursor(NULL, IDC_ARROW); 
    WindowClassEx.hbrBackground = NULL; 
	WindowClassEx.lpszMenuName = NULL; 
    WindowClassEx.lpszClassName = "Terrain"; 
	WindowClassEx.hIconSm = NULL; 
 
	ShowCursor(false); 
     
    RegisterClassEx( &WindowClassEx ); 
 
	hWnd = CreateWindowEx(  WS_EX_TOPMOST, // extended window style 
						    "Terrain", // pointer to registered class name 
						    "Terrain", // pointer to window name 
							WS_POPUP | WS_VISIBLE, // window style 
							0, // horizontal position of window 
							0, // vertical position of window 
							WIN_WIDTH, // window width 
							WIN_HEIGHT, // window height 
							NULL, // handle to parent or owner window 
							NULL, // handle to menu, or child-window identifier 
							hInstance, // handle to application instance 
							NULL // pointer to window-creation data 
						 ); 
 
	g_pApp = new cApp(); 
 
    ShowWindow( hWnd, SW_SHOWDEFAULT ); 
    UpdateWindow( hWnd ); 
 
	if(SUCCEEDED(g_pApp->Init())) 
	{ 
		MSG msg; 
		ZeroMemory( &msg, sizeof(msg) ); 
		while( msg.message!=WM_QUIT ) 
		{ 
			if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) 
			{ 
				TranslateMessage( &msg ); 
				DispatchMessage( &msg ); 
			} 
			else 
			{ 
				if(FAILED(g_pApp->Render())) 
				{ 
					MessageBox( hWnd, "g_pApp->Render() Failed!", "while( MainLoop )", MB_OK ); 
					PostQuitMessage( 0 ); 
				} 
			} 
		} 
	} 
 
	SafeDelete(g_pApp); 
 
    UnregisterClass( "Terrain", WindowClassEx.hInstance ); 
    return 0; 
} 
 
 
 
 
//----------------------------------------------------------------------------- 
// Name: MsgProc() 
// Desc: The window's message handler 
//----------------------------------------------------------------------------- 
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) 
{ 
    switch( msg ) 
    { 
        case WM_DESTROY: 
            PostQuitMessage( 0 ); 
            return 0; 
	} 
    return DefWindowProc( hWnd, msg, wParam, lParam ); 
}