Clone of Akilla's ac2d @ https://github.com/deregtd/AC2D

AC2DTest.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // AC2DTest.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "AC2DTest.h"
  5. #include "cClient.h"
  6. #define MAX_LOADSTRING 100
  7. // Global Variables:
  8. HINSTANCE hInst; // current instance
  9. cClient *Client;
  10. // Forward declarations of functions included in this code module:
  11. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  12. int APIENTRY _tWinMain(HINSTANCE hInstance,
  13. HINSTANCE hPrevInstance,
  14. LPTSTR lpCmdLine,
  15. int nCmdShow)
  16. {
  17. // Show command line parameters
  18. if (lpCmdLine[0] == 0) {
  19. MessageBox(NULL, "No command line parameters were supplied", "Error!", MB_OK);
  20. }
  21. else {
  22. MessageBox(NULL, lpCmdLine, "Commmand Line Parameters:", MB_OK);
  23. }
  24. hInst = hInstance;
  25. // _CrtSetDbgFlag ( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF );
  26. // Initialize global strings
  27. WNDCLASSEX wcex;
  28. wcex.cbSize = sizeof(WNDCLASSEX);
  29. wcex.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  30. wcex.lpfnWndProc = (WNDPROC)WndProc;
  31. wcex.cbClsExtra = 64;
  32. wcex.cbWndExtra = 0;
  33. wcex.hInstance = hInst;
  34. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_AC2DTEST);
  35. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  36. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  37. wcex.lpszMenuName = (LPCTSTR)IDC_AC2DTEST;
  38. wcex.lpszClassName = "AC2D";
  39. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_ICON1);
  40. RegisterClassEx(&wcex);
  41. HWND hWnd = CreateWindow("AC2D", "AC2D", WS_OVERLAPPEDWINDOW,
  42. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  43. srand((DWORD) time(0));
  44. if (!hWnd)
  45. return FALSE;
  46. //Now initialize our Client...
  47. Client = new cClient(hInst, hWnd);
  48. //Launch client
  49. Client->Start();
  50. ShowWindow(hWnd, nCmdShow);
  51. UpdateWindow(hWnd);
  52. MSG msg;
  53. HACCEL hAccelTable;
  54. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_AC2DTEST);
  55. // Main message loop:
  56. while (GetMessage(&msg, NULL, 0, 0))
  57. {
  58. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  59. {
  60. TranslateMessage(&msg);
  61. DispatchMessage(&msg);
  62. }
  63. }
  64. Client->Stop();
  65. delete Client;
  66. //_CrtDumpMemoryLeaks();
  67. return (int) msg.wParam;
  68. }
  69. //
  70. // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  71. //
  72. // PURPOSE: Processes messages for the main window.
  73. //
  74. // WM_COMMAND - process the application menu
  75. // WM_PAINT - Paint the main window
  76. // WM_DESTROY - post a quit message and return
  77. //
  78. //
  79. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  80. {
  81. int wmId, wmEvent;
  82. PAINTSTRUCT ps;
  83. HDC hdc;
  84. if (Client)
  85. {
  86. while (!Client->Initted())
  87. Sleep(1);
  88. Client->WindowsMessage(message, wParam, lParam);
  89. }
  90. switch (message)
  91. {
  92. case WM_COMMAND:
  93. wmId = LOWORD(wParam);
  94. wmEvent = HIWORD(wParam);
  95. // Parse the menu selections:
  96. switch (wmId)
  97. {
  98. case IDM_EXIT:
  99. DestroyWindow(hWnd);
  100. break;
  101. default:
  102. return DefWindowProc(hWnd, message, wParam, lParam);
  103. }
  104. break;
  105. case WM_PAINT:
  106. hdc = BeginPaint(hWnd, &ps);
  107. // TODO: Add any drawing code here...
  108. EndPaint(hWnd, &ps);
  109. break;
  110. case WM_SIZE:
  111. Client->Resize();
  112. break;
  113. case WM_DESTROY:
  114. PostQuitMessage(0);
  115. break;
  116. default:
  117. return DefWindowProc(hWnd, message, wParam, lParam);
  118. }
  119. return 0;
  120. }
  121. void _ODS( const char *fmt, ... )
  122. {
  123. va_list valist;
  124. va_start( valist, fmt );
  125. char szText[2048];
  126. memset( szText, 0, 2048 );
  127. _vsnprintf( szText, 2048, fmt, valist );
  128. OutputDebugString( szText );
  129. va_end( valist );
  130. }