Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include <cstdlib>
- #include <fstream>
- #include <cstring>
- #include <stdio.h>
- using namespace std;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- HWND btn1, btn2, childWnd, childWnd1, childWnd2, childWnd3, Click, hMainWnd, childWnd4, childWnd5, childWndst3, childWndst2, childWndst1, childWndst4;
- int selected_mark = 0;
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- WNDCLASSEX wc;
- char szClassName[] = "AppClass";
- wc.cbSize = sizeof(wc);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = szClassName;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- /*****************************************************************************************************************************/
- if (!RegisterClassEx(&wc)) {
- MessageBox(NULL, "Не удалось зарегистрировать класс окна", "Ошибка", MB_OK);
- return 0;
- }
- hMainWnd = CreateWindow(szClassName, "Программа работа(21)", WS_SYSMENU | WS_MINIMIZEBOX, 400, 200, 300, 300, NULL, NULL, hInstance, NULL);
- if (!hMainWnd) {
- MessageBox(NULL, "Не удалось создать главное окно программы", "Ошибка", MB_OK);
- return 0;
- }
- ShowWindow(hMainWnd, nCmdShow);
- /*Функция GetMessage возвращает FALSE, если получит сообщение WM_QUIT. Во всех остальных случаях она вернёт TRUE.*/
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg) {
- case WM_CREATE: {
- childWnd = CreateWindow("BUTTON", "Сохранить", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 65, 209, 150, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
- childWnd1 = CreateWindow("edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 16, 150, 30, hWnd, NULL, NULL, NULL);
- childWnd2 = CreateWindow("edit", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 61, 150, 30, hWnd, NULL, NULL, NULL);
- childWnd3 = CreateWindow("edit", NULL, WS_VISIBLE | WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 108, 150, 30, hWnd, NULL, NULL, NULL);
- childWnd4 = CreateWindow("LISTBOX", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER, 122, 147, 125, 60, hWnd, NULL, NULL, NULL);
- btn1 = CreateWindow("BUTTON", "/\\", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 250, 147, 30, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
- btn2 = CreateWindow("BUTTON", "\\/", WS_VISIBLE | WS_CHILD | BS_PUSHLIKE, 250, 180, 30, 30, hWnd, NULL, (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
- childWndst1 = CreateWindow("static", "Фамилия", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 16, 70, 30, hWnd, NULL, NULL, NULL);
- childWndst2 = CreateWindow("static", "Имя", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 61, 70, 30, hWnd, NULL, NULL, NULL);
- childWndst3 = CreateWindow("static", "Отчество", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 108, 70, 30, hWnd, NULL, NULL, NULL);
- childWndst4 = CreateWindow("static", "Оценка", WS_VISIBLE | WS_CHILD | SS_SIMPLE, 20, 147, 70, 30, hWnd, NULL, NULL, NULL);
- for (int i = 1; i < 11; i++) {
- char buf[20];
- _itoa_s(i, buf, 10);
- SendMessage(childWnd4, LB_ADDSTRING, 0, LPARAM(buf));
- }
- SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true);
- EnableWindow(childWnd, FALSE);
- break;
- }
- case WM_COMMAND: {
- if ((HWND)lParam == btn1) {
- if (selected_mark - 1 < 0) break;
- selected_mark--;
- SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true); //Изменяем позицию листбокс
- }
- else if ((HWND)lParam == btn2) {
- if (selected_mark - 1 > 9) break;
- selected_mark++;
- SendMessage(childWnd4, LB_SETCURSEL, (LPARAM)selected_mark, true); // Изменяем позицию листбокс
- }
- else if ((HWND)lParam == childWnd) {
- char bufa[20];
- char buffer[200];
- _itoa_s(selected_mark + 1, bufa, 10);
- ofstream f("list.txt", ios_base::app);
- char* buff = new char[1024];
- GetWindowText(childWnd1, buff, 100);
- f << buff << " ";
- GetWindowText(childWnd2, buff, 100);
- f << buff << " ";
- GetWindowText(childWnd3, buff, 100);
- f << buff << " ";
- f << bufa << "\n";
- delete buff;
- f.close();
- //MessageBox(NULL, buffer, buffer, 0);
- }
- EnableWindow(childWnd, FALSE);
- char buff[100];
- GetWindowText(childWnd1, buff, 100);
- if (strlen(buff) < 1) break;
- GetWindowText(childWnd2, buff, 100);
- if (strlen(buff) < 1) break;
- GetWindowText(childWnd3, buff, 100);
- if (strlen(buff) < 1) break;
- EnableWindow(childWnd, TRUE);
- break;
- }
- case WM_KEYUP: {
- break;
- }
- case WM_CLOSE: {
- DestroyWindow(hWnd); //посылает окну сообщение WM_DESTROY, после которого окна на экране уже нет
- break;
- }
- case WM_DESTROY: {
- PostQuitMessage(0); //посылает сообщение WM_QUIT, после которого прекращается цикл обработки сообщений
- break;
- }
- default: {
- return DefWindowProc(hWnd, uMsg, wParam, lParam); //обработка сообщений по умолчанию
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment