Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <windowsx.h>
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- //#define ID_TextArea 3002
- HINSTANCE hInst;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK Wndchild(HWND, UINT, WPARAM, LPARAM);
- int RegClass();
- HWND hwndR;
- HWND hwndL;
- HWND savebutton; //дескриптор кнопки Сохранить
- HWND Cancelbuttom; //дескриптор кнопки Отмена
- HWND TextName; // дестриптор "edit" де будет именя файла
- HWND TextArea; // дестриптор "edit"где впишется текст
- char chText[70]; //имя файла
- char Text[100]; // текст файла
- int N=0;
- int Regchil()
- {
- WNDCLASS wc;
- memset(&wc, 0, sizeof(WNDCLASS));
- wc.lpfnWndProc = Wndchild;
- wc.hInstance = hInst;
- wc.hIcon = LoadIcon(NULL, IDC_ARROW);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockBrush(COLOR_WINDOW);
- wc.lpszClassName = L"child";
- return RegisterClass(&wc);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCndShow)
- {
- MSG Msg;
- RegClass();
- int x = GetSystemMetrics(SM_CXSCREEN);
- int y = GetSystemMetrics(SM_CYSCREEN);
- HWND hwnd = CreateWindow(L"MainWindow", L"программа(вариант 16)", WS_OVERLAPPEDWINDOW | WS_SIZEBOX, x / 3, y / 3, x / 2 - 350, y / 2 - 40, NULL, NULL, hInst, NULL);
- ShowWindow(hwnd, nCndShow);
- TextName = CreateWindow(L"edit", L"text.txt", WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 300, 20, hwnd, (HMENU)3001 , hInstance, NULL);
- ShowWindow(TextName, nCndShow);
- TextArea = CreateWindow(L"edit", L"", WS_CHILD | WS_BORDER| ES_MULTILINE, 50, 80, 300, 200, hwnd, (HMENU)3002, hInst, NULL);
- ShowWindow(TextArea, nCndShow);
- savebutton = CreateWindow(L"button", L"Сохранить", WS_CHILD | BS_PUSHBUTTON | WS_VISIBLE | WS_BORDER, 50, 290, 85, 50, hwnd, (HMENU)3003, hInst, NULL);
- ShowWindow(savebutton, nCndShow);
- Cancelbuttom = CreateWindow(L"button", L"отменить", WS_CHILD | WS_VISIBLE | WS_BORDER, 265, 290, 85, 50, hwnd, (HMENU)3004, hInst, NULL);
- ShowWindow(Cancelbuttom, true);
- //SendMessage(TextArea, EM_SETREADONLY, false, 0);
- while (GetMessage(&Msg, NULL, 0, 0)) DispatchMessage(&Msg);
- return 0;
- }
- int RegClass()
- {
- WNDCLASS wc;
- memset(&wc, 0, sizeof(WNDCLASS));
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInst;
- wc.hIcon = LoadIcon(NULL, IDC_ARROW);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
- //wc.hbrBackground = GetStockBrush(COLOR_WINDOW);
- wc.lpszClassName = L"MainWindow";
- return RegisterClass(&wc);
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lparam)
- {
- ofstream Write;
- wfstream read;
- switch (msg) {
- case WM_COMMAND:
- {
- switch (LOWORD(wParam)) {
- case 3003:
- wchar_t name[100];
- memset(&name, 100, sizeof(name));
- GetWindowText(TextName, (LPWSTR)name, 15);
- Write.open(name);
- wchar_t Area[100];
- memset(&Area, 100, sizeof(Area));
- N = GetWindowText(TextArea, Area, 100);
- MessageBox(TextArea, Area, L"Текст файла ", MB_OK);
- for (int i = 0;i < N;i++) {
- Write << (char)Area[i];
- }
- Write.close();
- break;
- case 3004:
- read.open(name);
- wchar_t str[100];
- memset(&str, 100, sizeof(str));
- //read >> Area;
- GetDlgItemText(hwnd, 1, str, 20);
- SetWindowText(TextArea, (LPWSTR)str);
- read.close();
- break;
- return DefWindowProc(hwnd, msg, wParam, lparam);
- }
- break;
- }
- case WM_DESTROY: {
- PostQuitMessage(0);
- return 0;
- }
- default:
- return(DefWindowProc(hwnd, msg, wParam, lparam));
- }
- }
- LRESULT CALLBACK Wndchild(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- /*file.open("text.txt");
- if (!file) {
- //file.close();
- MessageBox(hwnd, L"Не найдет файл text.txt", L"Ошибка!", 0);
- return 0;
- }
- SetWindowText(TextArea, L"Поц...");
- file.close();*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement