Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.04 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <tchar.h>
  5. #include "resource.h"
  6. #include "STL.h"
  7. #include <iostream>
  8. #include <string> // std::string, std::wstring
  9. #include <algorithm> // std::copy
  10.  
  11. using namespace std;
  12.  
  13. wstring StringToWString(const string& s)
  14. {
  15. wstring temp(s.length(), L' ');
  16. copy(s.begin(), s.end(), temp.begin());
  17. return temp;
  18. }
  19.  
  20. string WStringToString(const wstring& s)
  21. {
  22. string temp(s.length(), ' ');
  23. copy(s.begin(), s.end(), temp.begin());
  24. return temp;
  25. }
  26.  
  27. LRESULT CALLBACK MainWinProc(HWND, UINT, WPARAM, LPARAM);
  28. LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
  29. HWND hMainWnd, hWnd;
  30. HINSTANCE hInst;
  31. char info[] = "Данная программа выполняет операции с последовательностями на основе STL.";
  32. char info2[] = "FILEVERSION 1.0.0.0 \nPRODUCTVERSION 1.0.0.0\nCOMPANYNAME - <PeppaEntertainment>\nFILEDESCRIPTION - <Программа для работы с последовательностями на основе STL.>\nLEGALCOPYRIGHT - Copyright (C) 2017";
  33. #define ID_MYBUTTON 1 /* идентификатор для кнопочки внутри главного окна */
  34.  
  35. BOOL NewWindowClass(WNDPROC Proc, TCHAR name[])
  36. {
  37. WNDCLASS stl;
  38. stl.style = CS_HREDRAW | CS_VREDRAW;
  39. stl.lpfnWndProc = Proc;
  40. stl.cbClsExtra = stl.cbWndExtra = 0;
  41. stl.hInstance = hInst;
  42. stl.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON2));
  43. stl.hCursor = LoadCursor(NULL, IDC_ARROW);
  44. stl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  45. stl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
  46. stl.lpszClassName = name;
  47.  
  48. if (!RegisterClass(&stl))
  49. {
  50. MessageBox(NULL, "Ошибка создания", "Error", NULL);
  51. return 1;
  52. }
  53. }
  54.  
  55. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int ss) {
  56.  
  57. hInst = hInstance;
  58. /* создаем и регистрируем класс главного окна */
  59. if (!NewWindowClass(MainWinProc, "STL")) return FALSE;
  60. /* создаем и регистрируем класс дочернего окна */
  61. if (!NewWindowClass(WinProc, "STL2")) return FALSE;
  62.  
  63. /* создаем главное окно и отображаем его */
  64. hMainWnd = CreateWindow("STL", "STL.Работа с последовательностями", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL);
  65. if (!hMainWnd) return FALSE;
  66. ShowWindow(hMainWnd, ss);
  67. UpdateWindow(hMainWnd);
  68.  
  69. MSG msg; /* цикл обработки событий главного окна */
  70. while (GetMessage(&msg, NULL, 0, 0)) {
  71. TranslateMessage(&msg);
  72. DispatchMessage(&msg);
  73. }
  74. return msg.wParam;
  75. }
  76.  
  77. /* процедура обработки сообщений для главного окна */
  78. LRESULT CALLBACK MainWinProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
  79. static HWND size_A = 0, size_B = 0, size_C = 0, A, B, C, Concat_AB, Subst_BC, Array;
  80. char array_A[100] = " ";
  81. char array_B[100] = " ";
  82. char array_C[100] = " ";
  83. char array_Concat[200] = " ";
  84. char array_Subst[100] = " ";
  85. char array_value[200] = " ";
  86.  
  87. TCHAR char_A[4], char_B[4], char_C[4];
  88. HINSTANCE hInst;
  89. PAINTSTRUCT paint;
  90. HDC hdc;
  91.  
  92. switch (msg) {
  93. /*case ID_MYBUTTON:
  94. SetWindowPos(hWnd, HWND_NOTOPMOST, 200, 200, 100, 100, NULL);
  95. EnableWindow(hMainWnd, FALSE); // делаем главное окно неактивным
  96. ShowWindow(hWnd, SW_SHOWNORMAL); // отображаем дочернее окно
  97. UpdateWindow(hMainWnd);
  98. break;*/
  99. case WM_CREATE:
  100. /* при создании окна внедряем в него кнопочку генерации */
  101. CreateWindow("button", "Генерация", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, 850, 400, 120, 30, hw, (HMENU)ID_MYBUTTON,NULL, NULL);
  102.  
  103. size_A = CreateWindow("EDIT", "3", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 50, 30, 20, hw, 0, NULL, NULL);
  104. ShowWindow(size_A, SW_SHOWNORMAL);
  105. size_B = CreateWindow("EDIT", "4", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 100, 30, 20, hw, 0, NULL, NULL);
  106. ShowWindow(size_B, SW_SHOWNORMAL);
  107. size_C = CreateWindow("EDIT", "7", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 150, 30, 20, hw, 0, NULL, NULL);
  108. ShowWindow(size_C, SW_SHOWNORMAL);
  109.  
  110. A = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 50, 620, 20, hw, 0, NULL, NULL);
  111. ShowWindow(A, SW_SHOWNORMAL);
  112. B = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 100, 620, 20, hw, 0, NULL, NULL);
  113. ShowWindow(B, SW_SHOWNORMAL);
  114. C = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 150, 620, 20, hw, 0, NULL, NULL);
  115. ShowWindow(C, SW_SHOWNORMAL);
  116. return 0;
  117. case WM_COMMAND:
  118. srand(time(NULL));
  119. if ((HIWORD(wp) == 0)) {
  120. switch (LOWORD(wp)) {
  121. case 40006:
  122. MessageBox(hw, info, "About", MB_OK | MB_ICONINFORMATION);
  123. break;
  124. case 40010:
  125. MessageBox(hw, info2,"Version", MB_OK | MB_ICONINFORMATION);
  126. break;
  127. case 40004:
  128. PostQuitMessage(0);
  129. }
  130. }
  131. if (LOWORD(wp) == ID_MYBUTTON) {
  132. MessageBox(hw, "Генерация выполнена", "Генерация множеств", MB_OK | MB_ICONINFORMATION);
  133. if (!IsWindow(hWnd))
  134. hWnd = CreateWindow("STL2", "Результат работы программы", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
  135. TREE tree_A, tree_B, tree_C, tree_D, tree_E;
  136. wchar_t d[100];
  137. GetWindowText(size_A, char_A, 4);
  138. GetWindowText(size_B, char_B, 4);
  139. GetWindowText(size_C, char_C, 4);
  140. int size_1 = atoi(char_A);
  141. int size_2 = atoi(char_B);
  142. int size_3 = atoi(char_C);
  143.  
  144. /*Генерация и вывод последовательности А*/
  145. Generate(tree_A, size_1);
  146. Output(tree_A, array_A);
  147. mbstowcs(d, array_A, sizeof(array_A) / sizeof(char));
  148. LPCWSTR string_a = d;
  149. string narrow_str_a(WStringToString(string_a));
  150. LPCSTR win_str_a = narrow_str_a.c_str();
  151. SetWindowText(A, win_str_a);
  152.  
  153. /*Генерация и вывод последовательности B*/
  154. Generate(tree_B, size_2);
  155. Output(tree_B, array_B);
  156. mbstowcs(d, array_B, sizeof(array_B) / sizeof(char));
  157. LPCWSTR string_b = d;
  158. string narrow_str_b(WStringToString(string_b));
  159. LPCSTR win_str_b = narrow_str_b.c_str();
  160. SetWindowText(B, win_str_b);
  161.  
  162. /*Генерация и вывод последовательности С*/
  163. Generate(tree_C, size_3);
  164. Output(tree_C, array_C);
  165. mbstowcs(d, array_C, sizeof(array_C) / sizeof(char));
  166. LPCWSTR string_c = d;
  167. string narrow_str_c(WStringToString(string_c));
  168. LPCSTR win_str_c = narrow_str_c.c_str();
  169. SetWindowText(C, win_str_c);
  170. }
  171. return 0;
  172. case WM_PAINT:
  173. hdc = BeginPaint(hw, &paint);
  174. TextOut(hdc, 5, 50, "Размер A", _tcslen("Мощность A"));
  175. TextOut(hdc, 5, 100, "Размер B", _tcslen("Мощность A"));
  176. TextOut(hdc, 5, 150, "Размер C", _tcslen("Мощность A"));
  177. EndPaint(hw, &paint);
  178. break;
  179. }
  180. return DefWindowProc(hw, msg, wp, lp);
  181. }
  182.  
  183. LRESULT CALLBACK WinProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
  184. static HWND size_A = 0, size_B = 0, size_C = 0, A, B, C, Concat_AB, Subst_BC, Array;
  185. char array_A[100] = " ";
  186. char array_B[100] = " ";
  187. char array_C[100] = " ";
  188. char array_Concat[200] = " ";
  189. char array_Subst[100] = " ";
  190. char array_value[200] = " ";
  191. TCHAR char_A[4], char_B[4], char_C[4];
  192. HINSTANCE hInst;
  193. PAINTSTRUCT paint;
  194. HDC hdc;
  195. switch (msg) {
  196. /*case WM_CLOSE:
  197. SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, NULL); // изменяем до нуля размеры и позицию дочернего окна
  198. ShowWindow(hWnd, SW_HIDE); // прячем дочернее окно
  199. EnableWindow(hMainWnd, TRUE); // разблокируем главное окно
  200. SetWindowPos(hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); // делаем главное окно верхним не изменяя его размеров и позиции
  201. break;*/
  202. case WM_CREATE:
  203. hInst = ((LPCREATESTRUCT)lp)->hInstance;
  204. Subst_BC = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 50, 620, 20, hw, 0, hInst, NULL);
  205. ShowWindow(Subst_BC, SW_SHOWNORMAL);
  206. Concat_AB = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 100, 620, 20, hw, 0, hInst, NULL);
  207. ShowWindow(Concat_AB, SW_SHOWNORMAL);
  208. Array = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 150, 620, 20, hw, 0, hInst, NULL);
  209. ShowWindow(Array, SW_SHOWNORMAL);
  210. case WM_COMMAND:
  211. srand(time(NULL));
  212. if ((HIWORD(wp) == 0)) {
  213. switch (LOWORD(wp)) {
  214. case 40006:
  215. MessageBox(hw, info, "About", MB_OK | MB_ICONINFORMATION);
  216. break;
  217. case 40010:
  218. MessageBox(hw, info2, "Version", MB_OK | MB_ICONINFORMATION);
  219. break;
  220. case 40004:
  221. PostQuitMessage(0);
  222. }
  223. }
  224. if (LOWORD(wp) == ID_MYBUTTON) {
  225. TREE tree_A, tree_B, tree_C, tree_D, tree_E;
  226. wchar_t d[100];
  227. GetWindowText(size_A, char_A, 4);
  228. GetWindowText(size_B, char_B, 4);
  229. GetWindowText(size_C, char_C, 4);
  230. int size_1 = atoi(char_A);
  231. int size_2 = atoi(char_B);
  232. int size_3 = atoi(char_C);
  233.  
  234. /*Слияние А и B*/
  235. tree_D = Concat(tree_A, tree_B);
  236. Output(tree_D, array_Concat);
  237. mbstowcs(d, array_Concat, sizeof(array_Concat) / sizeof(char));
  238. LPCWSTR string_concat = d;
  239. string narrow_str_concat(WStringToString(string_concat));
  240. LPCSTR win_str_concat = narrow_str_concat.c_str();
  241. SetWindowText(Concat_AB, win_str_concat);
  242.  
  243. /*Включение B в C с 3-ей позиции*/
  244. tree_E = Subst(tree_C, tree_B, 3);
  245. Output(tree_E, array_Subst);
  246. mbstowcs(d, array_Subst, sizeof(array_Subst) / sizeof(char));
  247. LPCWSTR string_subst = d;
  248. string narrow_str_subst(WStringToString(string_subst));
  249. LPCSTR win_str_subst = narrow_str_subst.c_str();
  250. SetWindowText(Subst_BC, win_str_subst);
  251.  
  252. /*Вывод множества - А|B&С*/
  253. vector <int> vec1 = Converting(tree_A), vec2 = Converting(tree_B), vec3 = Converting(tree_C), result_1, result_2;
  254. set_union(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), back_inserter(result_1));
  255. set_intersection(result_1.begin(), result_1.end(), vec3.begin(), vec3.end(), back_inserter(result_2));
  256. OutputString(result_2, array_value);
  257. mbstowcs(d, array_value, sizeof(array_value) / sizeof(char));
  258. LPCWSTR string_value = d;
  259. string narrow_str_value(WStringToString(string_value));
  260. LPCSTR win_str_value = narrow_str_value.c_str();
  261. SetWindowText(Array, win_str_value);
  262. }
  263. return 0;
  264. case WM_PAINT:
  265. hdc = BeginPaint(hw, &paint);
  266. TextOut(hdc, 5, 50, "Слияние A и B", _tcslen("Слияние A и B"));
  267. TextOut(hdc, 5, 100, "Включение B в C", _tcslen("Включение A и B"));
  268. TextOut(hdc, 5, 150, "A | B & C", _tcslen(_T("A | B & C")));
  269. EndPaint(hw, &paint);
  270. break;
  271.  
  272. }
  273. return DefWindowProc(hw, msg, wp, lp);
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement