winmain.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
- #include "global.h"
- #include "console.h"
- //-----------------------------------------------------------------------------
- // Global variables
- //-----------------------------------------------------------------------------
- bool g_bActive = false;
- HWND hMainWnd, hChildWnd;
- TCHAR *szWndTitle = "Asider Tank Alpha3";
- // game console
- ConsoleNet console;
- //-----------------------------------------------------------------------------
- // Callback procedures for windows
- //-----------------------------------------------------------------------------
- LRESULT CALLBACK MainWndProc( HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam );
- LRESULT CALLBACK GameWndProc( HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam );
- //-----------------------------------------------------------------------------
- // Network functions
- //-----------------------------------------------------------------------------
- bool InitNetwork( const char *serv_addr, unsigned int serv_port );
- //-----------------------------------------------------------------------------
- // Name: WinMain()
- // Desc: Main procedure
- //-----------------------------------------------------------------------------
- int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
- PSTR szCmdLine, int iCmdShow )
- {
- MSG msg;
- WNDCLASSEX wndclassex;
- // Create and show the main window
- wndclassex.cbSize = sizeof(WNDCLASSEX);
- wndclassex.style = CS_HREDRAW | CS_VREDRAW;
- wndclassex.lpfnWndProc = MainWndProc;
- wndclassex.cbClsExtra = 0;
- wndclassex.cbWndExtra = 0;
- wndclassex.hInstance = hInstance;
- wndclassex.hIcon = LoadIcon( hInstance,MAKEINTRESOURCE( IDI_TANK ) );
- wndclassex.hCursor = LoadCursor( NULL, IDC_ARROW);
- wndclassex.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
- wndclassex.lpszMenuName = NULL;
- wndclassex.lpszClassName = "MainWndClass";
- wndclassex.hIconSm = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_TANK ) );
- if( !RegisterClassEx( &wndclassex ) )
- return 0;
- hMainWnd = CreateWindow ( "MainWndClass",
- szWndTitle,
- WS_OVERLAPPEDWINDOW^WS_SIZEBOX^WS_MAXIMIZEBOX,
- 10,10,660,680,
- NULL,NULL,
- hInstance,NULL );
- if( !hMainWnd )
- return 0;
- ShowWindow( hMainWnd, iCmdShow );
- UpdateWindow( hMainWnd );
- // Create the game window as a child of the main one
- wndclassex.lpfnWndProc = GameWndProc;
- wndclassex.hInstance = hInstance;
- wndclassex.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
- wndclassex.lpszClassName = "GameWndClass";
- wndclassex.hIcon = NULL;
- wndclassex.hIconSm = NULL;
- if ( !RegisterClassEx ( &wndclassex ) )
- return 0;
-
- hChildWnd = CreateWindow ( "GameWndClass",
- NULL,
- WS_CHILDWINDOW | WS_VISIBLE,
- 0,0,640,640,
- hMainWnd,
- (HMENU)10, // child id 10
- hInstance,
- NULL );
- if( !hChildWnd )
- return 0;
- // Initialize network
- if( !InitNetwork("127.0.0.1",5500) )
- return 0;
- // Set focus to game window
- SetFocus( hChildWnd );
- // Message cycle
- while(true)
- {
- if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
- {
- if(msg.message == WM_QUIT)
- break;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- console.GameMain();
- }
- return 0;
- }