Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <stdio.h>
- #include <cstdio>
- #include <tchar.h>
- #define INPUT_ID 100
- #define RADIO1_ID 101
- #define RADIO2_ID 102
- #define OUTPUT_ID 103
- #define MIN_SIZE_X 500
- #define MIN_SIZE_Y 500
- #define CONVERSION_FACTOR 2.54
- #define CONVERT_TYPE_1 "Cale"
- #define CONVERT_TYPE_2 "Centymetry"
- RECT WndRect;
- HWND hwnd , Input, Radio_1, Radio_2, Output;
- //SendMessage(radio1, BM_GETCHECK, 0, 0) == 1;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
- switch (msg) {
- case WM_COMMAND: {}break;
- case WM_TIMER: {
- char buff[255];
- GetWindowText(Input, buff, 255);
- float Number = 0.0;
- if (SendMessage(Radio_1, BM_GETCHECK, 0, 0) == 1) {
- Number = atof(buff) * CONVERSION_FACTOR;
- }else if (SendMessage(Radio_2, BM_GETCHECK, 0, 0) == 1) {
- Number = atof(buff) / CONVERSION_FACTOR;
- }
- sprintf_s(buff, "%f", Number);
- SetWindowText(Output, buff);
- }break;
- case WM_SIZE: {
- GetClientRect(hwnd, &WndRect);
- MoveWindow(Input, (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 80, 200, 30, 1);
- MoveWindow(Radio_1, (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 40, 200, 30, 1);
- MoveWindow(Radio_2, (WndRect.right / 2) - 100, (WndRect.bottom / 2) , 200, 30, 1);
- MoveWindow(Output, (WndRect.right / 2) - 100, (WndRect.bottom / 2) + 40, 200, 50, 1);
- MapWindowPoints(0, GetParent(hwnd), (LPPOINT)&WndRect, 2);
- if (WndRect.right <= MIN_SIZE_X) {
- MoveWindow(hwnd, WndRect.left, WndRect.top, MIN_SIZE_X+1, WndRect.bottom - WndRect.top, 1);
- }
- if (WndRect.bottom <= MIN_SIZE_Y) {
- MoveWindow(hwnd, WndRect.left, WndRect.top, WndRect.right - WndRect.left, MIN_SIZE_Y+1, 1);
- }
- }break;
- case WM_CLOSE: DestroyWindow(hwnd); break;
- case WM_DESTROY: PostQuitMessage(0); break;
- default: return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
- WNDCLASSEX window;
- MSG msg;
- TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
- window.cbClsExtra = NULL;
- window.cbSize = sizeof(WNDCLASSEX);
- window.cbWndExtra = NULL;
- window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- window.hCursor = LoadCursor(NULL, IDC_ARROW);
- window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- window.hInstance = hInstance;
- window.lpfnWndProc = WndProc;
- window.lpszClassName = Class_Name;
- window.lpszMenuName = 0;
- window.style = CS_VREDRAW | CS_HREDRAW;
- RegisterClassEx(&window);
- hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- GetClientRect(hwnd, &WndRect);
- Input = CreateWindowEx(WS_EX_WINDOWEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
- (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 80, 200, 30, hwnd, (HMENU)INPUT_ID, hInstance, NULL);
- Radio_1 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", CONVERT_TYPE_1, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP,
- (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 40, 200, 30, hwnd, (HMENU)RADIO1_ID, hInstance, NULL);
- Radio_2 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", CONVERT_TYPE_2, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
- (WndRect.right / 2) - 100, (WndRect.bottom / 2) , 200, 30, hwnd, (HMENU)RADIO2_ID, hInstance, NULL);
- Output = CreateWindowEx(WS_EX_WINDOWEDGE, "STATIC", "WYNIK", WS_CHILD | WS_VISIBLE,
- (WndRect.right / 2) - 100, (WndRect.bottom / 2) + 40, 200, 50, hwnd, (HMENU)OUTPUT_ID, hInstance, NULL);
- SendMessage(Radio_1, BM_SETCHECK, 1, 0);
- SetTimer(hwnd, 1, 200, NULL);
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- UnregisterClass(Class_Name, hInstance);
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement