Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <windows.h>
- #include <time.h>
- #include <tchar.h>
- #include "resource.h"
- #include "STL.h"
- #include <iostream>
- #include <string> // std::string, std::wstring
- #include <algorithm> // std::copy
- using namespace std;
- wstring StringToWString(const string& s)
- {
- wstring temp(s.length(), L' ');
- copy(s.begin(), s.end(), temp.begin());
- return temp;
- }
- string WStringToString(const wstring& s)
- {
- string temp(s.length(), ' ');
- copy(s.begin(), s.end(), temp.begin());
- return temp;
- }
- LRESULT CALLBACK MainWinProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
- HWND hMainWnd, hWnd;
- HINSTANCE hInst;
- char info[] = "Данная программа выполняет операции с последовательностями на основе STL.";
- char info2[] = "FILEVERSION 1.0.0.0 \nPRODUCTVERSION 1.0.0.0\nCOMPANYNAME - <PeppaEntertainment>\nFILEDESCRIPTION - <Программа для работы с последовательностями на основе STL.>\nLEGALCOPYRIGHT - Copyright (C) 2017";
- #define ID_MYBUTTON 1 /* идентификатор для кнопочки внутри главного окна */
- BOOL NewWindowClass(WNDPROC Proc, TCHAR name[])
- {
- WNDCLASS stl;
- stl.style = CS_HREDRAW | CS_VREDRAW;
- stl.lpfnWndProc = Proc;
- stl.cbClsExtra = stl.cbWndExtra = 0;
- stl.hInstance = hInst;
- stl.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON2));
- stl.hCursor = LoadCursor(NULL, IDC_ARROW);
- stl.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- stl.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
- stl.lpszClassName = name;
- if (!RegisterClass(&stl))
- {
- MessageBox(NULL, "Ошибка создания", "Error", NULL);
- return 1;
- }
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int ss) {
- hInst = hInstance;
- /* создаем и регистрируем класс главного окна */
- if (!NewWindowClass(MainWinProc, "STL")) return FALSE;
- /* создаем и регистрируем класс дочернего окна */
- if (!NewWindowClass(WinProc, "STL2")) return FALSE;
- /* создаем главное окно и отображаем его */
- hMainWnd = CreateWindow("STL", "STL.Работа с последовательностями", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInst, NULL);
- if (!hMainWnd) return FALSE;
- ShowWindow(hMainWnd, ss);
- UpdateWindow(hMainWnd);
- MSG msg; /* цикл обработки событий главного окна */
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- /* процедура обработки сообщений для главного окна */
- LRESULT CALLBACK MainWinProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
- static HWND size_A = 0, size_B = 0, size_C = 0, A, B, C, Concat_AB, Subst_BC, Array;
- char array_A[100] = " ";
- char array_B[100] = " ";
- char array_C[100] = " ";
- char array_Concat[200] = " ";
- char array_Subst[100] = " ";
- char array_value[200] = " ";
- TCHAR char_A[4], char_B[4], char_C[4];
- HINSTANCE hInst;
- PAINTSTRUCT paint;
- HDC hdc;
- switch (msg) {
- /*case ID_MYBUTTON:
- SetWindowPos(hWnd, HWND_NOTOPMOST, 200, 200, 100, 100, NULL);
- EnableWindow(hMainWnd, FALSE); // делаем главное окно неактивным
- ShowWindow(hWnd, SW_SHOWNORMAL); // отображаем дочернее окно
- UpdateWindow(hMainWnd);
- break;*/
- case WM_CREATE:
- /* при создании окна внедряем в него кнопочку генерации */
- CreateWindow("button", "Генерация", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE, 850, 400, 120, 30, hw, (HMENU)ID_MYBUTTON,NULL, NULL);
- size_A = CreateWindow("EDIT", "3", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 50, 30, 20, hw, 0, NULL, NULL);
- ShowWindow(size_A, SW_SHOWNORMAL);
- size_B = CreateWindow("EDIT", "4", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 100, 30, 20, hw, 0, NULL, NULL);
- ShowWindow(size_B, SW_SHOWNORMAL);
- size_C = CreateWindow("EDIT", "7", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT, 90, 150, 30, 20, hw, 0, NULL, NULL);
- ShowWindow(size_C, SW_SHOWNORMAL);
- A = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 50, 620, 20, hw, 0, NULL, NULL);
- ShowWindow(A, SW_SHOWNORMAL);
- B = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 100, 620, 20, hw, 0, NULL, NULL);
- ShowWindow(B, SW_SHOWNORMAL);
- C = CreateWindow("STATIC", " ", WS_CHILD | WS_VISIBLE, 130, 150, 620, 20, hw, 0, NULL, NULL);
- ShowWindow(C, SW_SHOWNORMAL);
- return 0;
- case WM_COMMAND:
- srand(time(NULL));
- if ((HIWORD(wp) == 0)) {
- switch (LOWORD(wp)) {
- case 40006:
- MessageBox(hw, info, "About", MB_OK | MB_ICONINFORMATION);
- break;
- case 40010:
- MessageBox(hw, info2,"Version", MB_OK | MB_ICONINFORMATION);
- break;
- case 40004:
- PostQuitMessage(0);
- }
- }
- if (LOWORD(wp) == ID_MYBUTTON) {
- MessageBox(hw, "Генерация выполнена", "Генерация множеств", MB_OK | MB_ICONINFORMATION);
- if (!IsWindow(hWnd))
- hWnd = CreateWindow("STL2", "Результат работы программы", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
- TREE tree_A, tree_B, tree_C, tree_D, tree_E;
- wchar_t d[100];
- GetWindowText(size_A, char_A, 4);
- GetWindowText(size_B, char_B, 4);
- GetWindowText(size_C, char_C, 4);
- int size_1 = atoi(char_A);
- int size_2 = atoi(char_B);
- int size_3 = atoi(char_C);
- /*Генерация и вывод последовательности А*/
- Generate(tree_A, size_1);
- Output(tree_A, array_A);
- mbstowcs(d, array_A, sizeof(array_A) / sizeof(char));
- LPCWSTR string_a = d;
- string narrow_str_a(WStringToString(string_a));
- LPCSTR win_str_a = narrow_str_a.c_str();
- SetWindowText(A, win_str_a);
- /*Генерация и вывод последовательности B*/
- Generate(tree_B, size_2);
- Output(tree_B, array_B);
- mbstowcs(d, array_B, sizeof(array_B) / sizeof(char));
- LPCWSTR string_b = d;
- string narrow_str_b(WStringToString(string_b));
- LPCSTR win_str_b = narrow_str_b.c_str();
- SetWindowText(B, win_str_b);
- /*Генерация и вывод последовательности С*/
- Generate(tree_C, size_3);
- Output(tree_C, array_C);
- mbstowcs(d, array_C, sizeof(array_C) / sizeof(char));
- LPCWSTR string_c = d;
- string narrow_str_c(WStringToString(string_c));
- LPCSTR win_str_c = narrow_str_c.c_str();
- SetWindowText(C, win_str_c);
- }
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hw, &paint);
- TextOut(hdc, 5, 50, "Размер A", _tcslen("Мощность A"));
- TextOut(hdc, 5, 100, "Размер B", _tcslen("Мощность A"));
- TextOut(hdc, 5, 150, "Размер C", _tcslen("Мощность A"));
- EndPaint(hw, &paint);
- break;
- }
- return DefWindowProc(hw, msg, wp, lp);
- }
- LRESULT CALLBACK WinProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) {
- static HWND size_A = 0, size_B = 0, size_C = 0, A, B, C, Concat_AB, Subst_BC, Array;
- char array_A[100] = " ";
- char array_B[100] = " ";
- char array_C[100] = " ";
- char array_Concat[200] = " ";
- char array_Subst[100] = " ";
- char array_value[200] = " ";
- TCHAR char_A[4], char_B[4], char_C[4];
- HINSTANCE hInst;
- PAINTSTRUCT paint;
- HDC hdc;
- switch (msg) {
- /*case WM_CLOSE:
- SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, NULL); // изменяем до нуля размеры и позицию дочернего окна
- ShowWindow(hWnd, SW_HIDE); // прячем дочернее окно
- EnableWindow(hMainWnd, TRUE); // разблокируем главное окно
- SetWindowPos(hMainWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); // делаем главное окно верхним не изменяя его размеров и позиции
- break;*/
- case WM_CREATE:
- hInst = ((LPCREATESTRUCT)lp)->hInstance;
- Subst_BC = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 50, 620, 20, hw, 0, hInst, NULL);
- ShowWindow(Subst_BC, SW_SHOWNORMAL);
- Concat_AB = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 100, 620, 20, hw, 0, hInst, NULL);
- ShowWindow(Concat_AB, SW_SHOWNORMAL);
- Array = CreateWindow("STATIC", " ", SS_BLACKFRAME | WS_CHILD | WS_VISIBLE, 130, 150, 620, 20, hw, 0, hInst, NULL);
- ShowWindow(Array, SW_SHOWNORMAL);
- case WM_COMMAND:
- srand(time(NULL));
- if ((HIWORD(wp) == 0)) {
- switch (LOWORD(wp)) {
- case 40006:
- MessageBox(hw, info, "About", MB_OK | MB_ICONINFORMATION);
- break;
- case 40010:
- MessageBox(hw, info2, "Version", MB_OK | MB_ICONINFORMATION);
- break;
- case 40004:
- PostQuitMessage(0);
- }
- }
- if (LOWORD(wp) == ID_MYBUTTON) {
- TREE tree_A, tree_B, tree_C, tree_D, tree_E;
- wchar_t d[100];
- GetWindowText(size_A, char_A, 4);
- GetWindowText(size_B, char_B, 4);
- GetWindowText(size_C, char_C, 4);
- int size_1 = atoi(char_A);
- int size_2 = atoi(char_B);
- int size_3 = atoi(char_C);
- /*Слияние А и B*/
- tree_D = Concat(tree_A, tree_B);
- Output(tree_D, array_Concat);
- mbstowcs(d, array_Concat, sizeof(array_Concat) / sizeof(char));
- LPCWSTR string_concat = d;
- string narrow_str_concat(WStringToString(string_concat));
- LPCSTR win_str_concat = narrow_str_concat.c_str();
- SetWindowText(Concat_AB, win_str_concat);
- /*Включение B в C с 3-ей позиции*/
- tree_E = Subst(tree_C, tree_B, 3);
- Output(tree_E, array_Subst);
- mbstowcs(d, array_Subst, sizeof(array_Subst) / sizeof(char));
- LPCWSTR string_subst = d;
- string narrow_str_subst(WStringToString(string_subst));
- LPCSTR win_str_subst = narrow_str_subst.c_str();
- SetWindowText(Subst_BC, win_str_subst);
- /*Вывод множества - А|B&С*/
- vector <int> vec1 = Converting(tree_A), vec2 = Converting(tree_B), vec3 = Converting(tree_C), result_1, result_2;
- set_union(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), back_inserter(result_1));
- set_intersection(result_1.begin(), result_1.end(), vec3.begin(), vec3.end(), back_inserter(result_2));
- OutputString(result_2, array_value);
- mbstowcs(d, array_value, sizeof(array_value) / sizeof(char));
- LPCWSTR string_value = d;
- string narrow_str_value(WStringToString(string_value));
- LPCSTR win_str_value = narrow_str_value.c_str();
- SetWindowText(Array, win_str_value);
- }
- return 0;
- case WM_PAINT:
- hdc = BeginPaint(hw, &paint);
- TextOut(hdc, 5, 50, "Слияние A и B", _tcslen("Слияние A и B"));
- TextOut(hdc, 5, 100, "Включение B в C", _tcslen("Включение A и B"));
- TextOut(hdc, 5, 150, "A | B & C", _tcslen(_T("A | B & C")));
- EndPaint(hw, &paint);
- break;
- }
- return DefWindowProc(hw, msg, wp, lp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement