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 hRadio1, hRadio2, hText1, hText2, hText3, hText4;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
- char buff1[50], buff2[50], buff3[50], buff4[50];
- float value,value2;
- 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, 600, NULL, NULL, hInstance, NULL);
- hRadio1 = CreateWindowEx(0, "BUTTON", "KM na METRY", WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
- 100, 100, 150, 30, hwnd, (HMENU)1, hInstance, NULL);
- hRadio2 = CreateWindowEx(0, "BUTTON", "METRY na KM", WS_CHILD | WS_VISIBLE | BS_CHECKBOX,
- 100, 100, 150, 30, hwnd, (HMENU)2, hInstance, NULL);
- hText1 = CreateWindowEx(0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 150, 20,
- hwnd, NULL, hInstance, NULL);
- hText3 = CreateWindowEx(0, "Static", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 50, 50, 150, 20,
- 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)
- {
- switch (msg)
- {
- case WM_COMMAND:
- if ((HWND)lParam == hRadio1)
- {
- CheckRadioButton(hwnd, 1, 2, 1);
- }
- if ((HWND)lParam == hRadio2)
- {
- CheckRadioButton(hwnd, 1, 2, 2);
- }
- if ((IsDlgButtonChecked(hwnd, 1) == BST_CHECKED) == 1)
- {
- GetWindowText(hText1, buff1, 50);
- value = atof(buff1);
- value *= 1000;
- sprintf_s(buff1, "%.02f", value);
- SetWindowText(hText3, buff1);
- }
- if ((IsDlgButtonChecked(hwnd, 2) == BST_CHECKED) == 1)
- {
- GetWindowText(hText1, buff1, 50);
- value = atof(buff1);
- value /= 1000;
- sprintf_s(buff1, "%.02f", value);
- SetWindowText(hText3, buff1);
- }
- break;
- case WM_CREATE:
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_SIZE:
- GetClientRect(hwnd, &Rect);
- MoveWindow(hText1, Rect.right / 2 - 150, Rect.bottom / 2 - 50, 80, 20, TRUE);
- MoveWindow(hText3, Rect.right / 2 + 80, Rect.bottom / 2 - 50, 80, 20, TRUE);
- MoveWindow(hRadio1, Rect.right / 2 - 60, Rect.bottom / 2 - 50, 120, 20, TRUE);
- MoveWindow(hRadio2, Rect.right / 2 - 60, Rect.bottom / 2 - 30, 120, 20, TRUE);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement