Advertisement
Alan468

Przlicznik WORKING

Nov 29th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <stdio.h>
  3. #include <cstdio>
  4. #include <tchar.h>
  5.  
  6. #define INPUT_ID 100
  7. #define RADIO1_ID 101
  8. #define RADIO2_ID 102
  9. #define OUTPUT_ID 103
  10.  
  11. #define MIN_SIZE_X 500
  12. #define MIN_SIZE_Y 500
  13. #define CONVERSION_FACTOR 2.54
  14. #define CONVERT_TYPE_1 "Cale"
  15. #define CONVERT_TYPE_2 "Centymetry"
  16.  
  17. RECT WndRect;
  18. HWND hwnd , Input, Radio_1, Radio_2, Output;
  19.  
  20. //SendMessage(radio1, BM_GETCHECK, 0, 0) == 1;
  21. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  22.     switch (msg) {
  23.     case WM_COMMAND: {}break;
  24.  
  25.     case WM_TIMER: {
  26.         char buff[255];
  27.         GetWindowText(Input, buff, 255);
  28.         float Number = 0.0;
  29.  
  30.         if (SendMessage(Radio_1, BM_GETCHECK, 0, 0) == 1) {
  31.             Number = atof(buff) * CONVERSION_FACTOR;
  32.         }else if (SendMessage(Radio_2, BM_GETCHECK, 0, 0) == 1) {
  33.             Number = atof(buff) / CONVERSION_FACTOR;
  34.         }
  35.  
  36.         sprintf_s(buff, "%f", Number);
  37.         SetWindowText(Output, buff);
  38.  
  39.     }break;
  40.  
  41.     case WM_SIZE: {
  42.         GetClientRect(hwnd, &WndRect);
  43.  
  44.         MoveWindow(Input,   (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 80, 200, 30, 1);
  45.         MoveWindow(Radio_1, (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 40, 200, 30, 1);
  46.         MoveWindow(Radio_2, (WndRect.right / 2) - 100, (WndRect.bottom / 2)     , 200, 30, 1);
  47.         MoveWindow(Output,  (WndRect.right / 2) - 100, (WndRect.bottom / 2) + 40, 200, 50, 1);
  48.  
  49.         MapWindowPoints(0, GetParent(hwnd), (LPPOINT)&WndRect, 2);
  50.  
  51.         if (WndRect.right <= MIN_SIZE_X) {
  52.             MoveWindow(hwnd, WndRect.left, WndRect.top, MIN_SIZE_X+1, WndRect.bottom - WndRect.top, 1);
  53.         }
  54.         if (WndRect.bottom <= MIN_SIZE_Y) {
  55.             MoveWindow(hwnd, WndRect.left, WndRect.top, WndRect.right - WndRect.left, MIN_SIZE_Y+1, 1);
  56.         }
  57.  
  58.     }break;
  59.  
  60.     case WM_CLOSE: DestroyWindow(hwnd); break;
  61.     case WM_DESTROY: PostQuitMessage(0); break;
  62.     default: return DefWindowProc(hwnd, msg, wParam, lParam);
  63.     }
  64.     return 0;
  65. }
  66.  
  67. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR ilCmdLine, int nCmdShow) {
  68.     WNDCLASSEX window;
  69.     MSG msg;
  70.     TCHAR Class_Name[] = TEXT("OKNO_TEST"), Title[] = TEXT("Tytul");
  71.  
  72.     window.cbClsExtra = NULL;
  73.     window.cbSize = sizeof(WNDCLASSEX);
  74.     window.cbWndExtra = NULL;
  75.     window.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  76.     window.hCursor = LoadCursor(NULL, IDC_ARROW);
  77.     window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  78.     window.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  79.     window.hInstance = hInstance;
  80.     window.lpfnWndProc = WndProc;
  81.     window.lpszClassName = Class_Name;
  82.     window.lpszMenuName = 0;
  83.     window.style = CS_VREDRAW | CS_HREDRAW;
  84.  
  85.     RegisterClassEx(&window);
  86.  
  87.     hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, Class_Name, Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);
  88.  
  89.     ShowWindow(hwnd, nCmdShow);
  90.     UpdateWindow(hwnd);
  91.    
  92.     GetClientRect(hwnd, &WndRect);
  93.  
  94.     Input = CreateWindowEx(WS_EX_WINDOWEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
  95.         (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 80, 200, 30, hwnd, (HMENU)INPUT_ID, hInstance, NULL);
  96.  
  97.     Radio_1 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", CONVERT_TYPE_1, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP,
  98.         (WndRect.right / 2) - 100, (WndRect.bottom / 2) - 40, 200, 30, hwnd, (HMENU)RADIO1_ID, hInstance, NULL);
  99.     Radio_2 = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", CONVERT_TYPE_2, WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
  100.         (WndRect.right / 2) - 100, (WndRect.bottom / 2)     , 200, 30, hwnd, (HMENU)RADIO2_ID, hInstance, NULL);
  101.  
  102.     Output = CreateWindowEx(WS_EX_WINDOWEDGE, "STATIC", "WYNIK", WS_CHILD | WS_VISIBLE,
  103.         (WndRect.right / 2) - 100, (WndRect.bottom / 2) + 40, 200, 50, hwnd, (HMENU)OUTPUT_ID, hInstance, NULL);
  104.    
  105.     SendMessage(Radio_1, BM_SETCHECK, 1, 0);
  106.  
  107.     SetTimer(hwnd, 1, 200, NULL);
  108.  
  109.     while (GetMessage(&msg, NULL, 0, 0)) {
  110.         TranslateMessage(&msg);
  111.         DispatchMessage(&msg);
  112.     }
  113.  
  114.     UnregisterClass(Class_Name, hInstance);
  115.     return msg.wParam;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement