Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <Windows.h>
- #include "stdio.h"
- #include <ctime>
- #define ID_PRZELICZ 501
- #define ID_C 502
- #define ID_F 503
- #define ID_licz 504
- TCHAR Class_Name[] = TEXT("OKNO_TEST");
- MSG Komunikat;
- int zmienna = 0;
- char ilosc[128];
- char value[32];
- HINSTANCE *hInst;
- HWND okno1, okno2;
- HWND pole, przycisk, checkbox_C, checkbox_F, edit;
- double wynik = 0;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg) {
- case WM_CREATE:
- CheckDlgButton(okno1, ID_C, BST_CHECKED); //ustaw "fajeczkę"
- CheckDlgButton(okno1, ID_F, BST_UNCHECKED); //usuń "fajeczkę"
- break;
- case WM_COMMAND:
- switch (wParam)
- {
- case ID_licz:
- GetWindowTextA(edit, value, 32);
- SetWindowTextA(pole, value);
- break;
- case ID_C:
- CheckDlgButton(okno1, ID_C, BST_CHECKED); //ustaw "fajeczkę"
- CheckDlgButton(okno1, ID_F, BST_UNCHECKED); //usuń "fajeczkę"
- break;
- case ID_F:
- CheckDlgButton(okno1, ID_F, BST_CHECKED); //ustaw "fajeczkę"
- CheckDlgButton(okno1, ID_C, BST_UNCHECKED); //usuń "fajeczkę"
- break;
- case ID_PRZELICZ:
- GetWindowTextA(edit, value, 32);
- wynik = atof(value);
- if (IsDlgButtonChecked(hwnd, ID_C) == BST_CHECKED)
- {
- wynik = ((5.0 / 9.0) * (wynik - 32.0));
- }
- else
- {
- wynik = ((5.0 / 9.0) * wynik + 32.0);
- }
- sprintf_s(value, "%f", wynik);
- SetWindowTextA(pole, value);
- break;
- default:
- //MessageBox(hwnd, TEXT("Zrobiłeś coś innego ;-)"), TEXT("Test"), MB_ICONINFORMATION);
- break;
- }
- break;
- case WM_LBUTTONDOWN:
- zmienna++;
- sprintf_s(ilosc, "%d", zmienna);
- SetWindowTextA(hwnd, ilosc);
- break;
- case WM_CLOSE:
- if ((MessageBox(hwnd, TEXT("Czy chcesz wyłączyć okno ?"), TEXT("Pytanie"), MB_OKCANCEL)) == IDOK)
- DestroyWindow(hwnd);
- else break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProcW(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- hInst = &hInstance;
- WNDCLASSEX window;
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(*hInst, IDC_ARROW);
- window.hIcon = LoadIcon(*hInst, IDI_APPLICATION);
- window.hIconSm = NULL;
- window.hInstance = *hInst;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = NULL;
- if (!RegisterClassEx(&window)) {
- MessageBox(NULL, TEXT("Zarejestrowanie klasy nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 1;
- }
- okno1 = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, TEXT("Okno 1"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, NULL, NULL, *hInst, NULL);
- if (okno1 == NULL) {
- MessageBox(NULL, TEXT("Stworzenie okna nieudane! =("), TEXT("WARNING"), MB_OK | MB_ICONWARNING);
- return 2;
- }
- pole = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("STATIC"), TEXT("0"), WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 10, 150, 30, okno1, NULL, hInstance, NULL),
- checkbox_C = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Z F na C"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 20, 45, 150, 30, okno1, (HMENU) ID_C, hInstance, NULL);
- checkbox_F = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Z C na F"), WS_CHILD | WS_VISIBLE | BS_CHECKBOX, 20, 75, 150, 30, okno1, (HMENU) ID_F, hInstance, NULL);
- edit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,20, 105, 150, 20, okno1, (HMENU) ID_licz , hInstance, NULL);
- przycisk = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("BUTTON"), TEXT("Przelicz"), WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 135, 150, 30, okno1, (HMENU)ID_PRZELICZ, hInstance, NULL),
- ShowWindow(okno1, nCmdShow);
- UpdateWindow(okno1);
- while (GetMessage(&Komunikat, NULL, 0, 0)) {
- TranslateMessage(&Komunikat);
- DispatchMessage(&Komunikat);
- }
- UnregisterClass(Class_Name, *hInst);
- return Komunikat.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement