Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdio.h>
- LRESULT CALLBACK ProceduraOkna(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
- const COLORREF backgroundColor = RGB(255, 255, 255);
- HINSTANCE hInstance;
- enum {CELSJUSZ, KELWIN, FAHRENHEIT};
- bool RejestracjaOkna(WNDCLASSEX &window)
- {
- window.cbSize = sizeof(WNDCLASSEX);
- window.style = CS_VREDRAW | CS_HREDRAW;
- window.lpfnWndProc = ProceduraOkna;
- window.cbClsExtra = 0;
- window.cbWndExtra = 0;
- window.hInstance = hInstance;
- window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- window.hCursor = LoadCursor(NULL, IDC_ARROW);
- window.hbrBackground = (HBRUSH)CreateSolidBrush(backgroundColor);
- window.lpszMenuName = NULL;
- window.lpszClassName = "StandardoweOkno";
- window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if (!RegisterClassEx(&window))
- {
- MessageBox(NULL, "Problem z rejestracją okna", "Rejestracja okna", MB_ICONERROR | MB_OK);
- return false;
- }
- return true;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCMD)
- {
- WNDCLASSEX window;
- if (!RejestracjaOkna(window))
- return 0;
- HWND uchwytOkna = 0;
- uchwytOkna = CreateWindowEx(
- 0,
- "StandardoweOkno",
- "Pierwsze okno",
- WS_OVERLAPPEDWINDOW,
- 100,
- 100,
- 260,
- 200,
- 0,
- 0,
- hInstance,
- 0);
- ShowWindow(uchwytOkna, SW_NORMAL);
- UpdateWindow(uchwytOkna);
- MSG msg;
- for (; ;)
- {
- if (0 != GetMessage(&msg, 0, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if (msg.message == WM_QUIT) break;
- }
- return (int)msg.wParam;
- }
- LRESULT CALLBACK ProceduraOkna(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- static HWND edit_C, edit_K, edit_F, static_C, static_K, static_F;
- switch (message)
- {
- case WM_CREATE:
- {
- HINSTANCE &hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
- edit_C = CreateWindowEx(NULL, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 1, 2, 3, 4, hWnd, (HMENU)0, hInstance, NULL);
- edit_K = CreateWindowEx(NULL, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 5, 6, 7, 8, hWnd, (HMENU)1, hInstance, NULL);
- edit_F = CreateWindowEx(NULL, TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 9, 10, 11, 12, hWnd, (HMENU)2, hInstance, NULL);
- static_C = CreateWindowEx(NULL, TEXT("STATIC"), TEXT("Celsjusz"), WS_CHILD | WS_VISIBLE | WS_BORDER, 13, 14, 15, 16, hWnd, (HMENU)3, hInstance, NULL);
- static_K = CreateWindowEx(NULL, TEXT("STATIC"), TEXT("Kelwin"), WS_CHILD | WS_VISIBLE | WS_BORDER, 17, 18, 19, 20, hWnd, (HMENU)4, hInstance, NULL);
- static_F = CreateWindowEx(NULL, TEXT("STATIC"), TEXT("Farenheit"), WS_CHILD | WS_VISIBLE | WS_BORDER, 21, 22, 23, 24, hWnd, (HMENU)5, hInstance, NULL);
- }
- break;
- case WM_SIZE:
- {
- RECT clientRect;
- GetClientRect(hWnd, &clientRect);
- int xEdit = (clientRect.right - 50) / 2;
- int y = 10;
- int xStatic = (clientRect.right - 190) / 2;
- int widthEdit = 100;
- int height = 20;
- int widthStatic = 70;
- /////////////////////////////////////////////////////////////////////////
- MoveWindow(static_C, xStatic, y, widthStatic, height, TRUE);
- MoveWindow(edit_C, xEdit, y, widthEdit, height, TRUE);
- /////////////////////////////////////////////////////////////////////////
- MoveWindow(static_K, xStatic, y += height + 10, widthStatic, height, TRUE);
- MoveWindow(edit_K, xEdit, y, widthEdit, height, TRUE);
- /////////////////////////////////////////////////////////////////////////
- MoveWindow(static_F, xStatic, y += height + 10, widthStatic, height, TRUE);
- MoveWindow(edit_F, xEdit, y, widthEdit, height, TRUE);
- /////////////////////////////////////////////////////////////////////////
- }
- break;
- case WM_COMMAND:
- {
- static char buff[11];
- static double temp_C = 0;
- static double temp_K = 0;
- static double temp_F = 0;
- switch (LOWORD(wParam))
- {
- case CELSJUSZ:
- {
- if (GetFocus() != (HWND)lParam)
- break;
- GetWindowTextA(edit_C, buff, 10);
- temp_C = atof(buff);
- temp_K = temp_C + 273.15;
- temp_F = 1.8 * temp_C + 32;
- sprintf_s(buff, "%.2lf", temp_K);
- SetWindowTextA(edit_K, buff);
- sprintf_s(buff, "%.2lf", temp_F);
- SetWindowTextA(edit_F, buff);
- }
- break;
- case KELWIN:
- {
- if (GetFocus() != (HWND)lParam)
- break;
- GetWindowTextA(edit_K, buff, 10);
- temp_K = atof(buff);
- temp_C = temp_K - 273.15;
- temp_F = 1.8 * temp_C + 32;
- sprintf_s(buff, "%.2lf", temp_C);
- SetWindowTextA(edit_C, buff);
- sprintf_s(buff, "%.2lf", temp_F);
- SetWindowTextA(edit_F, buff);
- }
- break;
- case FAHRENHEIT:
- {
- if (GetFocus() != (HWND)lParam)
- break;
- GetWindowTextA(edit_F, buff, 10);
- temp_F = atof(buff);
- temp_C = (5.0/9.0) * (temp_F -32);
- temp_K = temp_C + 273.15;
- sprintf_s(buff, "%.2lf", temp_C);
- SetWindowTextA(edit_C, buff);
- sprintf_s(buff, "%.2lf", temp_K);
- SetWindowTextA(edit_K, buff);
- }
- break;
- }
- }
- break;
- case WM_GETMINMAXINFO:
- ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 260;
- ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200;
- break;
- case WM_CLOSE:
- if (MessageBox(hWnd, "Czy chcesz zakonczyc dzialanie programu?", "Dzialanie programu", MB_YESNO | MB_ICONERROR) == IDNO)
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement