Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <math.h>
- #include <list>
- #include <stdio.h>
- using namespace std;
- LPCSTR NazwaKlasy = TEXT("Klasa Okienka");
- MSG Komunikat;
- HDC hdc;
- HWND hwnd;
- RECT Rect;
- HWND hTextWpisz, hButtonZmien, hTextCo, hTextNaCo, hTextWyswietl;
- SYSTEMTIME czasAktualny, czasStartu;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- 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)(COLOR_WINDOW + 1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = NazwaKlasy;
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&wc))
- {
- MessageBox(NULL, TEXT("Nie mozna utworzyc okna"), TEXT("Niestety..."),
- MB_ICONEXCLAMATION | MB_OK);
- return 1;
- }
- hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, NazwaKlasy, TEXT("Oto okienko"), WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 800, 400, NULL, NULL, hInstance, NULL);
- hTextWpisz = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
- hwnd, NULL, hInstance, NULL);
- hTextCo= CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
- hwnd, NULL, hInstance, NULL);
- hTextNaCo = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
- hwnd, NULL, hInstance, NULL);
- hTextWyswietl = CreateWindowEx(0, "Static", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 0, 0,
- hwnd, NULL, hInstance, NULL);
- hButtonZmien = CreateWindowEx(0, "BUTTON", "Zmien", WS_CHILD | WS_VISIBLE,
- 0, 0, 150, 30, hwnd, NULL, hInstance, NULL);
- if (hwnd == NULL)
- {
- MessageBox(NULL, TEXT("Okno odmówiło przyjścia na świat!"), TEXT("Ale kicha..."), MB_ICONEXCLAMATION);
- return 1;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&Komunikat, NULL, 0, 0))
- {
- TranslateMessage(&Komunikat);
- DispatchMessage(&Komunikat);
- }
- return Komunikat.wParam;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- char text[250];
- char co[2];
- char naco[2];
- switch (msg)
- {
- case WM_COMMAND:
- if ((HWND)lParam == hButtonZmien)
- {
- GetWindowText(hTextWpisz, text, 250);
- GetWindowText(hTextCo, co, 2);
- GetWindowText(hTextNaCo, naco, 2);
- for (int i = 0; i < 250; i++)
- {
- if (text[i] == co[0])
- {
- text[i] = naco[0];
- }
- }
- SetWindowText(hTextWyswietl, text);
- }
- break;
- case WM_CREATE:
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_SIZE:
- GetClientRect(hwnd, &Rect);
- MoveWindow(hTextWpisz, Rect.right / 2 - 75, Rect.bottom / 2 - 100, 150, 50, TRUE);
- MoveWindow(hTextCo, Rect.right / 2 - 25, Rect.bottom / 2 - 40, 25, 25, TRUE);
- MoveWindow(hTextNaCo, Rect.right / 2, Rect.bottom / 2 - 40, 25, 25, TRUE);
- MoveWindow(hButtonZmien, Rect.right / 2 - 25, Rect.bottom / 2 , 50, 25, TRUE);
- MoveWindow(hTextWyswietl, Rect.right / 2 -75, Rect.bottom / 2 + 30 , 150, 50, TRUE);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement