fursty

PS Calculator

Mar 2nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. // Not.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Not.h"
  6.  
  7. #define MAX_LOADSTRING 100
  8. int a;
  9. int b;
  10. int c;
  11. // Global Variables:
  12. HINSTANCE hInst; // current instance
  13. TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
  14. TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
  15.  
  16. // Forward declarations of functions included in this code module:
  17. ATOM MyRegisterClass(HINSTANCE hInstance);
  18. BOOL InitInstance(HINSTANCE, int);
  19. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  20. INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  21. INT_PTR CALLBACK Calc(HWND, UINT, WPARAM, LPARAM);
  22.  
  23. int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
  24. _In_opt_ HINSTANCE hPrevInstance,
  25. _In_ LPTSTR lpCmdLine,
  26. _In_ int nCmdShow)
  27. {
  28. UNREFERENCED_PARAMETER(hPrevInstance);
  29. UNREFERENCED_PARAMETER(lpCmdLine);
  30.  
  31. // TODO: Place code here.
  32. MSG msg;
  33. HACCEL hAccelTable;
  34.  
  35. // Initialize global strings
  36. LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  37. LoadString(hInstance, IDC_NOT, szWindowClass, MAX_LOADSTRING);
  38. MyRegisterClass(hInstance);
  39.  
  40. // Perform application initialization:
  41. if (!InitInstance (hInstance, nCmdShow))
  42. {
  43. return FALSE;
  44. }
  45.  
  46. hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_NOT));
  47.  
  48. // Main message loop:
  49. while (GetMessage(&msg, NULL, 0, 0))
  50. {
  51. if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  52. {
  53. TranslateMessage(&msg);
  54. DispatchMessage(&msg);
  55. }
  56. }
  57.  
  58. return (int) msg.wParam;
  59. }
  60.  
  61.  
  62.  
  63. //
  64. // FUNCTION: MyRegisterClass()
  65. //
  66. // PURPOSE: Registers the window class.
  67. //
  68. ATOM MyRegisterClass(HINSTANCE hInstance)
  69. {
  70. WNDCLASSEX wcex;
  71.  
  72. wcex.cbSize = sizeof(WNDCLASSEX);
  73.  
  74. wcex.style = CS_HREDRAW | CS_VREDRAW;
  75. wcex.lpfnWndProc = WndProc;
  76. wcex.cbClsExtra = 0;
  77. wcex.cbWndExtra = 0;
  78. wcex.hInstance = hInstance;
  79. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NOT));
  80. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  81. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  82. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_NOT);
  83. wcex.lpszClassName = szWindowClass;
  84. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  85.  
  86. return RegisterClassEx(&wcex);
  87. }
  88.  
  89. //
  90. // FUNCTION: InitInstance(HINSTANCE, int)
  91. //
  92. // PURPOSE: Saves instance handle and creates main window
  93. //
  94. // COMMENTS:
  95. //
  96. // In this function, we save the instance handle in a global variable and
  97. // create and display the main program window.
  98. //
  99. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  100. {
  101. HWND hWnd;
  102.  
  103. hInst = hInstance; // Store instance handle in our global variable
  104.  
  105. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  106. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  107.  
  108. if (!hWnd)
  109. {
  110. return FALSE;
  111. }
  112.  
  113. ShowWindow(hWnd, nCmdShow);
  114. UpdateWindow(hWnd);
  115.  
  116. return TRUE;
  117. }
  118.  
  119. //
  120. // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  121. //
  122. // PURPOSE: Processes messages for the main window.
  123. //
  124. // WM_COMMAND - process the application menu
  125. // WM_PAINT - Paint the main window
  126. // WM_DESTROY - post a quit message and return
  127. //
  128. //
  129. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  130. {
  131. int wmId, wmEvent;
  132. PAINTSTRUCT ps;
  133. HDC hdc;
  134.  
  135. switch (message)
  136. {
  137. case WM_COMMAND:
  138. wmId = LOWORD(wParam);
  139. wmEvent = HIWORD(wParam);
  140. // Parse the menu selections:
  141. switch (wmId)
  142. {
  143. case IDM_ABOUT:
  144. DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  145. break;
  146.  
  147. case IDM_CALCULATOR:
  148. DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, Calc);
  149. break;
  150.  
  151. case IDM_EXIT:
  152. DestroyWindow(hWnd);
  153. break;
  154. default:
  155. return DefWindowProc(hWnd, message, wParam, lParam);
  156. }
  157. break;
  158. case WM_PAINT:
  159. hdc = BeginPaint(hWnd, &ps);
  160. // TODO: Add any drawing code here...
  161. EndPaint(hWnd, &ps);
  162. break;
  163. case WM_DESTROY:
  164. PostQuitMessage(0);
  165. break;
  166. default:
  167. return DefWindowProc(hWnd, message, wParam, lParam);
  168. }
  169. return 0;
  170. }
  171.  
  172. // Message handler for about box.
  173. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  174. {
  175. UNREFERENCED_PARAMETER(lParam);
  176. switch (message)
  177. {
  178. case WM_INITDIALOG:
  179. return (INT_PTR)TRUE;
  180.  
  181. case WM_COMMAND:
  182. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  183. {
  184. EndDialog(hDlg, LOWORD(wParam));
  185. return (INT_PTR)TRUE;
  186. }
  187. break;
  188. }
  189. return (INT_PTR)FALSE;
  190. }
  191.  
  192.  
  193.  
  194. INT_PTR CALLBACK Calc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  195. {
  196. UNREFERENCED_PARAMETER(lParam);
  197. switch (message)
  198. {
  199. case WM_INITDIALOG:
  200. return (INT_PTR)TRUE;
  201.  
  202. case WM_COMMAND:
  203. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  204. {
  205. EndDialog(hDlg, LOWORD(wParam));
  206. return (INT_PTR)TRUE;
  207. }
  208. break;
  209. }
  210.  
  211. switch (LOWORD(wParam))
  212. {
  213.  
  214. case IDC_Plus:
  215. {
  216. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  217. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  218. c=a+b;
  219. SetDlgItemInt(hDlg, IDC_Result, c, true);
  220. }break;
  221.  
  222. case IDC_Minus:
  223. {
  224. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  225. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  226. c=a-b;
  227. SetDlgItemInt(hDlg, IDC_Result, c, true);
  228. }break;
  229.  
  230. case IDC_Umnojenie:
  231. {
  232. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  233. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  234. c=a*b;
  235. SetDlgItemInt(hDlg, IDC_Result, c, true);
  236. }
  237. break;
  238.  
  239.  
  240. case IDC_Del:
  241. {
  242. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  243. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  244. c=a/b;
  245. SetDlgItemInt(hDlg, IDC_Result, c, true);
  246. }
  247. break;
  248.  
  249. case IDC_Stepen:
  250. {
  251. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  252. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  253. c=a^2;
  254. SetDlgItemInt(hDlg, IDC_Result, c, true);
  255. }
  256. break;
  257.  
  258. case IDC_Pro:
  259. {
  260. a = GetDlgItemInt(hDlg, IDC_EDITA, NULL, true);
  261. b = GetDlgItemInt(hDlg, IDC_EDITB, NULL, true);
  262. c=a%2;
  263. SetDlgItemInt(hDlg, IDC_Result, c, true);
  264. }
  265. break;
  266.  
  267. default:
  268. break;
  269. }
  270.  
  271.  
  272. return (INT_PTR)FALSE;
  273. }
Advertisement
Add Comment
Please, Sign In to add comment