Advertisement
Guest User

asdsad

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