Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- const wchar_t text[50] = L"Enter text and click the button.";
- static HWND textField;
- static HWND button;
- static HWND field1;
- static HWND field2;
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int CALLBACK wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR szCmdLine, int nCmdShow)
- {
- // структура, содержащая информацию о сообщениях
- MSG msg{};
- // структура, в которой хранитс¤ дескриптор окна (указатель на область пам¤ти в ¤дре)
- HWND hwnd{};
- // структура, отвечающа¤ за параметры окна
- WNDCLASSEX wc{ sizeof(WNDCLASSEX) };
- // параметры окна
- wc.hbrBackground = CreateSolidBrush(RGB(240, 240, 240));
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- wc.hInstance = hInstance;
- wc.lpfnWndProc = WndProc;
- wc.lpszClassName = L"MyClass";
- wc.style = CS_VREDRAW | CS_HREDRAW;
- // проверка регистрации окна
- if (!RegisterClassEx(&wc))
- return EXIT_FAILURE;
- // создание окна
- if (hwnd = CreateWindowW(wc.lpszClassName, L"Lab_1", WS_OVERLAPPEDWINDOW, 0, 0, 500, 200, NULL, NULL, wc.hInstance, NULL); hwnd == INVALID_HANDLE_VALUE)
- return EXIT_FAILURE;
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- // цикл сообщений
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return EXIT_SUCCESS;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_DESTROY:
- PostQuitMessage(EXIT_SUCCESS);
- break;
- case WM_CREATE:
- textField = CreateWindowW(L"STATIC", text, WS_CHILD | WS_VISIBLE | SS_CENTER, 50, 20, 350, 70, hWnd, NULL, NULL, NULL);
- button = CreateWindowW(L"BUTTON", L"Click!", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 180, 40, 100, 20, hWnd, (HMENU) 1, NULL, NULL);
- field1 = CreateWindowW(L"EDIT", L"", WS_BORDER | WS_CHILD | WS_VISIBLE | !ES_READONLY, 50, 70, 350, 20, hWnd, NULL, NULL, NULL);
- field2 = CreateWindowW(L"EDIT", L"", WS_BORDER | WS_CHILD | WS_VISIBLE | ES_READONLY, 50, 100, 350, 20, hWnd, NULL, NULL, NULL);
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case 1:
- WCHAR* buffer = new WCHAR[150];
- GetWindowText(field1, buffer, 150);
- // изменяет название окна
- SetWindowText(hWnd, buffer);
- // изменяет значение поля field2
- SetWindowText(field2, buffer);
- break;
- }
- break;
- }
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement