winmain.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. #include "global.h"
  2. #include "console.h"
  3. //-----------------------------------------------------------------------------
  4. // Global variables
  5. //-----------------------------------------------------------------------------
  6. bool g_bActive = false;
  7. HWND hMainWnd, hChildWnd;
  8. TCHAR *szWndTitle = "Asider Tank Alpha3";
  9. // game console
  10. ConsoleNet console;
  11. //-----------------------------------------------------------------------------
  12. // Callback procedures for windows
  13. //-----------------------------------------------------------------------------
  14. LRESULT CALLBACK MainWndProc( HWND hwnd, UINT message, 
  15.  WPARAM wParam, LPARAM lParam );
  16. LRESULT CALLBACK GameWndProc( HWND hwnd, UINT message,
  17.  WPARAM wParam, LPARAM lParam );
  18. //-----------------------------------------------------------------------------
  19. // Network functions
  20. //-----------------------------------------------------------------------------
  21. bool InitNetwork( const char *serv_addr, unsigned int serv_port );
  22. //-----------------------------------------------------------------------------
  23. // Name: WinMain()
  24. // Desc: Main procedure
  25. //-----------------------------------------------------------------------------
  26. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  27.    PSTR szCmdLine, int iCmdShow )
  28. {
  29. MSG msg;
  30. WNDCLASSEX  wndclassex;
  31. // Create and show the main window
  32. wndclassex.cbSize  = sizeof(WNDCLASSEX);
  33.     wndclassex.style         = CS_HREDRAW | CS_VREDRAW;
  34.     wndclassex.lpfnWndProc   = MainWndProc;
  35.     wndclassex.cbClsExtra    = 0;
  36.     wndclassex.cbWndExtra    = 0;
  37.     wndclassex.hInstance     = hInstance;
  38.     wndclassex.hIcon         = LoadIcon( hInstance,MAKEINTRESOURCE( IDI_TANK ) );
  39.     wndclassex.hCursor       = LoadCursor( NULL, IDC_ARROW);
  40.     wndclassex.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
  41.     wndclassex.lpszMenuName  = NULL;
  42.     wndclassex.lpszClassName = "MainWndClass";
  43. wndclassex.hIconSm  = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_TANK ) );
  44.    if( !RegisterClassEx( &wndclassex ) )
  45.         return 0;
  46. hMainWnd = CreateWindow ( "MainWndClass",
  47. szWndTitle,
  48. WS_OVERLAPPEDWINDOW^WS_SIZEBOX^WS_MAXIMIZEBOX,
  49. 10,10,660,680,
  50. NULL,NULL,
  51. hInstance,NULL );
  52. if( !hMainWnd )
  53. return 0;
  54. ShowWindow( hMainWnd, iCmdShow );
  55. UpdateWindow( hMainWnd );
  56. // Create the game window as a child of the main one
  57.     wndclassex.lpfnWndProc   = GameWndProc;
  58.     wndclassex.hInstance     = hInstance;
  59. wndclassex.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
  60.     wndclassex.lpszClassName = "GameWndClass";
  61. wndclassex.hIcon         = NULL;
  62. wndclassex.hIconSm  = NULL;
  63.    if ( !RegisterClassEx ( &wndclassex ) )
  64.          return 0;
  65.     
  66.   hChildWnd = CreateWindow ( "GameWndClass",
  67. NULL,
  68. WS_CHILDWINDOW | WS_VISIBLE,
  69. 0,0,640,640,
  70. hMainWnd,
  71. (HMENU)10, // child id 10
  72. hInstance,
  73. NULL );
  74. if( !hChildWnd )
  75. return 0;
  76. // Initialize network
  77. if( !InitNetwork("127.0.0.1",5500) )
  78. return 0;
  79. // Set focus to game window
  80. SetFocus( hChildWnd );
  81. // Message cycle
  82. while(true)
  83. {
  84. if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  85. {
  86. if(msg.message == WM_QUIT)
  87. break;
  88. TranslateMessage(&msg);
  89. DispatchMessage(&msg);
  90. }
  91. console.GameMain();
  92. }
  93. return 0;
  94. }