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

WindowLib.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // WindowLib.cpp : Defines the entry point for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "WindowLib.h"
  5. #include "CWindow.h"
  6. #include "CMessageBox.h"
  7. #include "CWindowManager.h"
  8. #include "Windows.h"
  9. #define MAX_LOADSTRING 100
  10. // Global Variables:
  11. HINSTANCE hInst; // current instance
  12. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  13. TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  14. // Forward declarations of functions included in this code module:
  15. ATOM MyRegisterClass(HINSTANCE hInstance);
  16. BOOL InitInstance(HINSTANCE, int);
  17. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  18. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  19. int APIENTRY WinMain(HINSTANCE hInstance,
  20. HINSTANCE hPrevInstance,
  21. LPTSTR lpCmdLine,
  22. int nCmdShow)
  23. {
  24. CWindowManager f;
  25. IWindow *g = new CWindow();
  26. //CWindow foo;
  27. CMessageBox foo;
  28. foo.Okay.OnButtonClick();
  29. // TODO: Place code here.
  30. MSG msg;
  31. HACCEL hAccelTable;
  32. // Initialize global strings
  33. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  34. LoadString(hInstance, IDC_WINDOWLIB, szWindowClass, MAX_LOADSTRING);
  35. MyRegisterClass(hInstance);
  36. // Perform application initialization:
  37. if (!InitInstance (hInstance, nCmdShow))
  38. {
  39. return FALSE;
  40. }
  41. hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINDOWLIB);
  42. // Main message loop:
  43. while (GetMessage(&msg, NULL, 0, 0))
  44. {
  45. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  46. {
  47. TranslateMessage(&msg);
  48. DispatchMessage(&msg);
  49. }
  50. }
  51. return (int) msg.wParam;
  52. }
  53. //
  54. // FUNCTION: MyRegisterClass()
  55. //
  56. // PURPOSE: Registers the window class.
  57. //
  58. // COMMENTS:
  59. //
  60. // This function and its usage are only necessary if you want this code
  61. // to be compatible with Win32 systems prior to the 'RegisterClassEx'
  62. // function that was added to Windows 95. It is important to call this function
  63. // so that the application will get 'well formed' small icons associated
  64. // with it.
  65. //
  66. ATOM MyRegisterClass(HINSTANCE hInstance)
  67. {
  68. WNDCLASSEX wcex;
  69. wcex.cbSize = sizeof(WNDCLASSEX);
  70. wcex.style = CS_HREDRAW | CS_VREDRAW;
  71. wcex.lpfnWndProc = (WNDPROC)WndProc;
  72. wcex.cbClsExtra = 0;
  73. wcex.cbWndExtra = 0;
  74. wcex.hInstance = hInstance;
  75. wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WINDOWLIB);
  76. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  77. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  78. wcex.lpszMenuName = (LPCTSTR)IDC_WINDOWLIB;
  79. wcex.lpszClassName = szWindowClass;
  80. wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
  81. return RegisterClassEx(&wcex);
  82. }
  83. //
  84. // FUNCTION: InitInstance(HANDLE, int)
  85. //
  86. // PURPOSE: Saves instance handle and creates main window
  87. //
  88. // COMMENTS:
  89. //
  90. // In this function, we save the instance handle in a global variable and
  91. // create and display the main program window.
  92. //
  93. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  94. {
  95. HWND hWnd;
  96. hInst = hInstance; // Store instance handle in our global variable
  97. hWnd = CreateWindowA(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  98. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  99. if (!hWnd)
  100. {
  101. return FALSE;
  102. }
  103. ShowWindow(hWnd, nCmdShow);
  104. UpdateWindow(hWnd);
  105. return TRUE;
  106. }
  107. //
  108. // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
  109. //
  110. // PURPOSE: Processes messages for the main window.
  111. //
  112. // WM_COMMAND - process the application menu
  113. // WM_PAINT - Paint the main window
  114. // WM_DESTROY - post a quit message and return
  115. //
  116. //
  117. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  118. {
  119. int wmId, wmEvent;
  120. PAINTSTRUCT ps;
  121. HDC hdc;
  122. switch (message)
  123. {
  124. case WM_COMMAND:
  125. wmId = LOWORD(wParam);
  126. wmEvent = HIWORD(wParam);
  127. // Parse the menu selections:
  128. switch (wmId)
  129. {
  130. case IDM_ABOUT:
  131. DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
  132. break;
  133. case IDM_EXIT:
  134. DestroyWindow(hWnd);
  135. break;
  136. default:
  137. return DefWindowProc(hWnd, message, wParam, lParam);
  138. }
  139. break;
  140. case WM_PAINT:
  141. hdc = BeginPaint(hWnd, &ps);
  142. // TODO: Add any drawing code here...
  143. EndPaint(hWnd, &ps);
  144. break;
  145. case WM_DESTROY:
  146. PostQuitMessage(0);
  147. break;
  148. default:
  149. return DefWindowProc(hWnd, message, wParam, lParam);
  150. }
  151. return 0;
  152. }
  153. // Message handler for about box.
  154. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  155. {
  156. switch (message)
  157. {
  158. case WM_INITDIALOG:
  159. return TRUE;
  160. case WM_COMMAND:
  161. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  162. {
  163. EndDialog(hDlg, LOWORD(wParam));
  164. return TRUE;
  165. }
  166. break;
  167. }
  168. return FALSE;
  169. }