alexx876

Untitled

Oct 24th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.62 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <fstream>
  5. #include <cstring>
  6. #include <stdio.h>
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  13.  
  14. HWND btn1, btn2, childWnd, childWnd1, childWnd2, childWnd3, Click, hMainWnd, childWnd4, childWnd5, childWndst3, childWndst2, childWndst1, childWndst4;
  15.  
  16. int selected_mark = 0;
  17.  
  18. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  19. {
  20.     MSG msg;
  21.     WNDCLASSEX wc;
  22.  
  23.     char szClassName[] = "AppClass";
  24.     wc.cbSize = sizeof(wc);
  25.     wc.style = CS_HREDRAW | CS_VREDRAW;
  26.     wc.lpfnWndProc = WndProc;
  27.     wc.cbClsExtra = 0;
  28.     wc.cbWndExtra = 0;
  29.     wc.hInstance = hInstance;
  30.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  32.     wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  33.     wc.lpszMenuName = NULL;
  34.     wc.lpszClassName = szClassName;
  35.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  36.     /*****************************************************************************************************************************/
  37.     if (!RegisterClassEx(&wc)) {
  38.         MessageBox(NULL, "Не удалось зарегистрировать класс окна", "Ошибка", MB_OK);
  39.         return 0;
  40.     }
  41.  
  42.     hMainWnd = CreateWindow(szClassName, "Программа работа(21)", WS_SYSMENU | WS_MINIMIZEBOX, 400, 200, 300, 300, NULL, NULL, hInstance, NULL);
  43.  
  44.     if (!hMainWnd) {
  45.         MessageBox(NULL, "Не удалось создать главное окно программы", "Ошибка", MB_OK);
  46.         return 0;
  47.     }
  48.     ShowWindow(hMainWnd, nCmdShow);
  49.  
  50.  
  51.     /*Функция GetMessage возвращает FALSE, если получит сообщение WM_QUIT. Во всех остальных случаях она вернёт TRUE.*/
  52.     while (GetMessage(&msg, NULL, 0, 0)) {
  53.         TranslateMessage(&msg);
  54.         DispatchMessage(&msg);
  55.     }
  56.  
  57.     return msg.wParam;
  58. }
  59.  
  60.  
  61. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  62. {
  63.  
  64.  
  65.  
  66.     switch (uMsg) {
  67.     case WM_CREATE: {
  68.  
  69.         childWnd = CreateWindow("BUTTON", "Сохранить", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 65, 209, 150, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  70.  
  71.         childWnd1 = CreateWindow("edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 16, 150, 30, hWnd, NULL, NULL, NULL);
  72.  
  73.         childWnd2 = CreateWindow("edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 61, 150, 30, hWnd, NULL, NULL, NULL);
  74.  
  75.         childWnd3 = CreateWindow("edit", NULL, WS_VISIBLE | WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 108, 150, 30, hWnd, NULL, NULL, NULL);
  76.  
  77.         childWnd4 = CreateWindow("LISTBOX", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 147, 125, 60, hWnd, NULL, NULL, NULL);
  78.  
  79.         btn1 = CreateWindow("BUTTON", "/\\", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 250, 147, 30, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  80.         btn2 = CreateWindow("BUTTON", "\\/", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 250, 180, 30, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
  81.  
  82.         childWndst1 = CreateWindow("static", "Фамилия", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 16, 70, 30, hWnd, NULL, NULL, NULL);
  83.  
  84.         childWndst2 = CreateWindow("static", "Имя", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 61, 70, 30, hWnd, NULL, NULL, NULL);
  85.  
  86.         childWndst3 = CreateWindow("static", "Отчество", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 108, 70, 30, hWnd, NULL, NULL, NULL);
  87.  
  88.         childWndst4 = CreateWindow("static", "Оценка", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 147, 70, 30, hWnd, NULL, NULL, NULL);
  89.         for (int i = 1; i < 11; i++) {
  90.             char buf[20];
  91.             _itoa_s(i, buf, 10);
  92.             SendMessage(childWnd4, LB_ADDSTRING, 0, LPARAM(buf));
  93.         }
  94.         SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true);
  95.         EnableWindow(childWnd, FALSE);
  96.         break;
  97.     }
  98.  
  99.     case WM_COMMAND: {
  100.         if ((HWND)lParam == btn1) {
  101.             if (selected_mark - 1 < 0) break;
  102.             selected_mark--;
  103.             SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true);  //Изменяем позицию листбокс
  104.         }
  105.         else if ((HWND)lParam == btn2) {
  106.             if (selected_mark - 1 > 9) break;
  107.             selected_mark++;
  108.             SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true); // Изменяем позицию листбокс
  109.         }
  110.         else if ((HWND)lParam == childWnd) {
  111.             char bufa[20];
  112.             char buffer[200];
  113.  
  114.             _itoa_s(selected_mark + 1, bufa, 10);
  115.             ofstream f("list.txt", ios_base::app);
  116.             char* buff = new char[1024];
  117.             GetWindowText(childWnd1, buff, 100);
  118.             f << buff << " ";
  119.  
  120.             GetWindowText(childWnd2, buff, 100);
  121.             f << buff << " ";
  122.  
  123.             GetWindowText(childWnd3, buff, 100);
  124.             f << buff << " ";
  125.  
  126.             f << bufa << "\n";
  127.             delete buff;
  128.  
  129.             f.close();
  130.  
  131.             //MessageBox(NULL, buffer, buffer, 0);
  132.         }
  133.         EnableWindow(childWnd, FALSE);
  134.         char buff[100];
  135.         GetWindowText(childWnd1, buff, 100);
  136.         if (strlen(buff) < 1) break;
  137.  
  138.         GetWindowText(childWnd2, buff, 100);
  139.         if (strlen(buff) < 1) break;
  140.  
  141.         GetWindowText(childWnd3, buff, 100);
  142.         if (strlen(buff) < 1) break;
  143.  
  144.         EnableWindow(childWnd, TRUE);
  145.         break;
  146.     }
  147.     case WM_KEYUP: {
  148.  
  149.  
  150.         break;
  151.     }
  152.  
  153.  
  154.     case WM_CLOSE: {
  155.         DestroyWindow(hWnd);    //посылает окну сообщение WM_DESTROY, после которого окна на экране уже нет
  156.         break;
  157.     }
  158.     case WM_DESTROY: {
  159.         PostQuitMessage(0);     //посылает сообщение WM_QUIT, после которого прекращается цикл обработки сообщений
  160.         break;
  161.     }
  162.     default: {
  163.         return DefWindowProc(hWnd, uMsg, wParam, lParam); //обработка сообщений по умолчанию
  164.     }
  165.     }
  166.  
  167.     return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment