Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. // lab02.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "lab02.h"
  6.  
  7. #define MAX_LOADSTRING 100
  8.  
  9. // Global Variables:
  10. HINSTANCE hInst; // current instance
  11. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  12. TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  13.  
  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. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  19.  
  20. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  21. _In_opt_ HINSTANCE hPrevInstance,
  22. _In_ LPTSTR lpCmdLine,
  23. _In_ int nCmdShow)
  24. {
  25. UNREFERENCED_PARAMETER(hPrevInstance);
  26. UNREFERENCED_PARAMETER(lpCmdLine);
  27.  
  28. // TODO: Place code here.
  29. MSG msg;
  30. HACCEL hAccelTable;
  31.  
  32. // Initialize global strings
  33. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  34. LoadString(hInstance, IDC_LAB02, szWindowClass, MAX_LOADSTRING);
  35. MyRegisterClass(hInstance);
  36.  
  37. // Perform application initialization:
  38. if (!InitInstance (hInstance, nCmdShow))
  39. {
  40. return FALSE;
  41. }
  42.  
  43. hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LAB02));
  44.  
  45. // Main message loop:
  46. while (GetMessage(&msg, NULL, 0, 0))
  47. {
  48. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  49. {
  50. TranslateMessage(&msg);
  51. DispatchMessage(&msg);
  52. }
  53. }
  54.  
  55. return (int) msg.wParam;
  56. }
  57.  
  58.  
  59.  
  60. //
  61. // FUNCTION: MyRegisterClass()
  62. //
  63. // PURPOSE: Registers the window class.
  64. //
  65. ATOM MyRegisterClass(HINSTANCE hInstance)
  66. {
  67. WNDCLASSEX wcex;
  68.  
  69. wcex.cbSize = sizeof(WNDCLASSEX);
  70.  
  71. wcex.style = CS_HREDRAW | CS_VREDRAW;
  72. wcex.lpfnWndProc = WndProc;
  73. wcex.cbClsExtra = 0;
  74. wcex.cbWndExtra = 0;
  75. wcex.hInstance = hInstance;
  76. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LAB02));
  77. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  78. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  79. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_LAB02);
  80. wcex.lpszClassName = szWindowClass;
  81. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  82.  
  83. return RegisterClassEx(&wcex);
  84. }
  85.  
  86. //
  87. // FUNCTION: InitInstance(HINSTANCE, int)
  88. //
  89. // PURPOSE: Saves instance handle and creates main window
  90. //
  91. // COMMENTS:
  92. //
  93. // In this function, we save the instance handle in a global variable and
  94. // create and display the main program window.
  95. //
  96. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  97. {
  98. HWND hWnd;
  99.  
  100. hInst = hInstance; // Store instance handle in our global variable
  101.  
  102. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  103. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  104.  
  105. if (!hWnd)
  106. {
  107. return FALSE;
  108. }
  109.  
  110. ShowWindow(hWnd, nCmdShow);
  111. UpdateWindow(hWnd);
  112.  
  113. return TRUE;
  114. }
  115.  
  116. //
  117. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  118. //
  119. // PURPOSE: Processes messages for the main window.
  120. //
  121. // WM_COMMAND - process the application menu
  122. // WM_PAINT - Paint the main window
  123. // WM_DESTROY - post a quit message and return
  124. //
  125. //
  126. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  127. {
  128. int wmId, wmEvent;
  129. PAINTSTRUCT ps;
  130. HDC hdc;
  131.  
  132. switch (message)
  133. {
  134. case WM_COMMAND:
  135. wmId = LOWORD(wParam);
  136. wmEvent = HIWORD(wParam);
  137. // Parse the menu selections:
  138. switch (wmId)
  139. {
  140. case IDM_MYFIRST:
  141. DialogBox(hInst, MAKEINTRESOURCE(IDD_DLG_MYFIRST), hWnd, About);
  142. break;
  143. case IDM_ABOUT:
  144. DialogBox(hInst, MAKEINTRESOURCE(IDD_DLG_MYFIRST), hWnd, About);
  145. break;
  146. case IDM_EXIT:
  147. DestroyWindow(hWnd);
  148. break;
  149. default:
  150. return DefWindowProc(hWnd, message, wParam, lParam);
  151. }
  152. break;
  153. case WM_PAINT:
  154. hdc = BeginPaint(hWnd, &ps);
  155. // TODO: Add any drawing code here...
  156. EndPaint(hWnd, &ps);
  157. break;
  158. case WM_DESTROY:
  159. PostQuitMessage(0);
  160. break;
  161. default:
  162. return DefWindowProc(hWnd, message, wParam, lParam);
  163. }
  164. return 0;
  165. }
  166.  
  167. // Message handler for about box.
  168. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  169. {
  170. UNREFERENCED_PARAMETER(lParam);
  171. switch (message)
  172. {
  173. case WM_INITDIALOG:
  174. return (INT_PTR)TRUE;
  175.  
  176. case WM_COMMAND:
  177. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  178. {
  179. int MSBOX=MessageBox(hDlg, L"do you ...", L"about exit" , MB_ICONEXCLAMATION | MB_OKCANCEL);
  180. if (MSBOX=IDOK)
  181. EndDialog(hDlg, LOWORD(wParam));
  182. return (INT_PTR)TRUE;
  183. }
  184. break;
  185. }
  186. return (INT_PTR)FALSE;
  187. }
  188. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  189. {
  190. UNREFERENCED_PARAMETER(lParam);
  191. switch (message)
  192. {
  193. case WM_INITDIALOG:
  194. return (INT_PTR)TRUE;
  195.  
  196. case WM_COMMAND:
  197. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  198. {
  199. int MSBOX=MessageBox(hDlg, L"do you ...", L"about exit" , MB_ICONEXCLAMATION | MB_OKCANCEL);
  200. if (MSBOX=IDOK)
  201. EndDialog(hDlg, LOWORD(wParam));
  202. return (INT_PTR)TRUE;
  203. }
  204. break;
  205. }
  206. return (INT_PTR)FALSE;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement