Hyluss

zbulwiony calc

Nov 29th, 2016
843
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define SCREEN_WIDTH 700
  2. #define SCREEN_HEIGHT 600
  3.  
  4. #define ID_BUTTON1 1
  5. #define ID_BUTTON2 2
  6. #define ID_BUTTON3 3
  7. #define ID_BUTTON4 4
  8. #define ID_BUTTON5 5
  9. #define ID_BUTTON6 6
  10. #define ID_BUTTON7 7
  11. #define ID_BUTTON8 8
  12. #define ID_BUTTON9 9
  13. #define ID_BUTTON0 0
  14.  
  15. #define ID_PLUS 11
  16. #define ID_MINUS 12
  17. #define ID_MNOZENIE 13
  18. #define ID_DZIELENIE 14
  19. #define ID_PRZECINEK 15
  20. #define ID_ROWNASIE 16
  21.  
  22. #define ID_VALUEFIELD1 400
  23.  
  24. #include <windows.h>
  25. #include <tchar.h>
  26.  
  27. TCHAR className[] = TEXT("NazwaKlasy");
  28. TCHAR appName[] = TEXT("Stoperan");
  29.  
  30. HWND hwnd;
  31. MSG msg;
  32.  
  33.  
  34.  
  35.  
  36.  
  37. /*
  38. void Przelicz(HWND hwnd)
  39. {
  40.     DWORD dl = (GetWindowTextLength (poletekstowe));
  41.     wchar_t Bufor[128];
  42.     GetWindowTextW (poletekstowe, Bufor , dl+1);
  43.     double value = _wtof (Bufor); // konwersja tekstu na liczbe
  44.  
  45.     if (BST_CHECKED == IsDlgButtonChecked (hwnd, CM_NA_CALE))
  46.     {
  47.         value = value / 2.5;
  48.     }
  49.     else
  50.     {
  51.         value = value * 2.5;
  52.     }
  53.     _swprintf (Bufor,L"%.2f",value); // wczytanie do bufora wartosci value
  54.     SetWindowTextW  (statik,Bufor);
  55. }
  56. */
  57.  
  58. wchar_t Bufor[100];
  59. int liczba=0;
  60.  
  61. void Wpisz (HWND &ValueField, char* znak)
  62. {   //ValueField
  63.     DWORD dl = (GetWindowTextLength (ValueField));
  64.    
  65.     if (znak == "0" || znak=="1" || znak=="2" || znak=="3" || znak=="4" || znak=="5" || znak=="6" || znak=="7" || znak=="8" || znak=="9")
  66.     {
  67.         int value = atof (znak);
  68.         _swprintf (&Bufor[dl],L"%d",value);
  69.         SetWindowText  (ValueField,Bufor);
  70.     }
  71.     else
  72.     {
  73.         if (znak == "+")
  74.         {  
  75.             _swprintf (&Bufor[dl],L"+");
  76.             SetWindowText  (ValueField,Bufor);
  77.         }
  78.     }
  79. }
  80.  
  81.  
  82. void Rozwiaz ( HWND &ValueField)
  83. {
  84.     DWORD dl = (GetWindowTextLength (ValueField));
  85.     wchar_t Wynik[128];
  86.     GetWindowTextW (ValueField, Wynik , dl+1);
  87.     double value = _wtof (Wynik); // konwersja tekstu na liczbe
  88. }
  89.  
  90. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  91. {
  92.     static RECT R;
  93.     static HWND ValueField, BUTTON3, BUTTON2, BUTTON1,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8,BUTTON9,BUTTON0, DODAJ, ODEJMIJ, POMNOZ, PODZIEL, ROWNASIE;
  94.  
  95.     switch (msg)
  96.     {
  97.         case WM_CREATE:
  98.         {
  99.              HINSTANCE &hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
  100.  
  101.              ValueField = CreateWindowEx (0,L"STATIC",NULL,WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_VALUEFIELD1, hInstance,0);
  102.              if (ValueField==0)
  103.              {
  104.                  MessageBox (hwnd,L"Problem z ValueField", className, MB_OK);
  105.                  return 1;
  106.              }
  107.    
  108.              BUTTON1 = CreateWindowEx (0,L"BUTTON",L"1",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON1, hInstance,0);
  109.              if (!BUTTON1)
  110.              {
  111.                  MessageBox (hwnd,L"Problem z BUTTON1", className, MB_OK);
  112.                  return 1;
  113.              }
  114.  
  115.              BUTTON2 = CreateWindowEx (0,L"BUTTON",L"2",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON2, hInstance,0);
  116.              if (!BUTTON2)
  117.              {
  118.                  MessageBox (hwnd,L"Problem z BUTTON2", className, MB_OK);
  119.                  return 1;
  120.              }
  121.  
  122.              BUTTON3 = CreateWindowEx (0,L"BUTTON",L"3",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON3, hInstance,0);
  123.              if (!BUTTON3)
  124.              {
  125.                  MessageBox (hwnd,L"Problem z BUTTON3", className, MB_OK);
  126.                  return 1;
  127.              }
  128.  
  129.              BUTTON4 = CreateWindowEx (0,L"BUTTON",L"Start",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON4, hInstance,0);
  130.              if (!BUTTON4)
  131.              {
  132.                  MessageBox (hwnd,L"Problem z BUTTON4", className, MB_OK);
  133.                  return 1;
  134.              }
  135.  
  136.              BUTTON5 = CreateWindowEx (0,L"BUTTON",L"Stop",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON5, hInstance,0);
  137.              if (!BUTTON5)
  138.              {
  139.                  MessageBox (hwnd,L"Problem z BUTTON5", className, MB_OK);
  140.                  return 1;
  141.              }
  142.  
  143.              BUTTON6 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON6, hInstance,0);
  144.              if (!BUTTON6)
  145.              {
  146.                  MessageBox (hwnd,L"Problem z BUTTON6", className, MB_OK);
  147.                  return 1;
  148.              }
  149.  
  150.  
  151.              BUTTON7 = CreateWindowEx (0,L"BUTTON",L"Start",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON7, hInstance,0);
  152.              if (!BUTTON7)
  153.              {
  154.                  MessageBox (hwnd,L"Problem z BUTTON7", className, MB_OK);
  155.                  return 1;
  156.              }
  157.  
  158.              BUTTON8 = CreateWindowEx (0,L"BUTTON",L"Stop",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON8, hInstance,0);
  159.              if (!BUTTON8)
  160.              {
  161.                  MessageBox (hwnd,L"Problem z BUTTON8", className, MB_OK);
  162.                  return 1;
  163.              }
  164.  
  165.              BUTTON9 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON9, hInstance,0);
  166.              if (!BUTTON9)
  167.              {
  168.                  MessageBox (hwnd,L"Problem z BUTTON9", className, MB_OK);
  169.                  return 1;
  170.              }
  171.  
  172.              BUTTON0 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON0, hInstance,0);
  173.              if (!BUTTON0)
  174.              {
  175.                  MessageBox (hwnd,L"Problem z BUTTON0", className, MB_OK);
  176.                  return 1;
  177.              }
  178.  
  179.              DODAJ = CreateWindowEx (0,L"BUTTON",L"Dodaj +",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_PLUS, hInstance,0);
  180.              if (!DODAJ)
  181.              {
  182.                  MessageBox (hwnd,L"Problem z DODAJ", className, MB_OK);
  183.                  return 1;
  184.              }
  185.  
  186.              ODEJMIJ = CreateWindowEx (0,L"BUTTON",L"ODEJMIJ -",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_MINUS, hInstance,0);
  187.              if (!ODEJMIJ)
  188.              {
  189.                  MessageBox (hwnd,L"Problem z ODEJMIJ", className, MB_OK);
  190.                  return 1;
  191.              }
  192.  
  193.              POMNOZ = CreateWindowEx (0,L"BUTTON",L"POMNOZ x",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_MNOZENIE, hInstance,0);
  194.              if (!POMNOZ)
  195.              {
  196.                  MessageBox (hwnd,L"Problem z POMNOZ", className, MB_OK);
  197.                  return 1;
  198.              }
  199.  
  200.              PODZIEL = CreateWindowEx (0,L"BUTTON",L"PODZIEL /",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_DZIELENIE, hInstance,0);
  201.              if (!PODZIEL)
  202.              {
  203.                  MessageBox (hwnd,L"Problem z PODZIEL", className, MB_OK);
  204.                  return 1;
  205.              }
  206.  
  207.              ROWNASIE = CreateWindowEx (0,L"BUTTON",L"ROWNA SIE =",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_ROWNASIE, hInstance,0);
  208.              if (!ROWNASIE)
  209.              {
  210.                  MessageBox (hwnd,L"Problem z ROWNASIE", className, MB_OK);
  211.                  return 1;
  212.              }
  213.  
  214.         }break;
  215.  
  216.         case WM_SIZE:
  217.             {
  218.             GetClientRect(hwnd, &R);        
  219.             MoveWindow(ValueField, R.right / 3, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
  220.             MoveWindow(BUTTON1, R.right / 3, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
  221.             MoveWindow(BUTTON2, R.right / 2, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
  222.             MoveWindow(BUTTON3, R.right / 2, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
  223.             MoveWindow(ROWNASIE,  R.right / 3, R.bottom / 2.5 + 60, R.right / 7, R.bottom / 15, 1);
  224.             MoveWindow(DODAJ,  R.right / 2, R.bottom / 2.5 + 60, R.right / 7, R.bottom / 15, 1);
  225.             }break;
  226.  
  227.         case WM_GETMINMAXINFO:
  228.             ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 550;
  229.             ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 400;
  230.             ((MINMAXINFO*)lParam)->ptMaxTrackSize.x = 1000;
  231.             ((MINMAXINFO*)lParam)->ptMaxTrackSize.y = 900;
  232.             break;
  233.  
  234.         case WM_COMMAND:
  235.             switch (wParam)
  236.             {
  237.                 case ID_BUTTON1:
  238.                     Wpisz (ValueField, "1");
  239.                     break;
  240.  
  241.                 case ID_BUTTON2:
  242.                      Wpisz (ValueField, "2");
  243.                     break;
  244.  
  245.                 case ID_BUTTON3:
  246.                      Wpisz (ValueField, "3");
  247.                     break;
  248.  
  249.                 case ID_PLUS:
  250.                      Wpisz (ValueField, "+");
  251.                      break;
  252.  
  253.                 case ID_ROWNASIE:
  254.                     SetWindowText (ValueField,L"Sam se kurwa policz");
  255.                     break;
  256.  
  257.             }break;
  258.            
  259.         case WM_CLOSE:
  260.             DestroyWindow(hwnd);  
  261.             break;
  262.  
  263.         case WM_DESTROY:
  264.             {
  265.                 PostQuitMessage(0);
  266.             }break;
  267.  
  268.         default:  
  269.             return DefWindowProc(hwnd, msg, wParam, lParam);
  270.     }
  271.     return 0;
  272. }
  273.  
  274. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  275. {
  276.     WNDCLASSEX wc;
  277.     wc.cbSize = sizeof(WNDCLASSEX);
  278.     wc.style = 0;
  279.     wc.cbClsExtra = 0;
  280.     wc.cbWndExtra = 0;
  281.     wc.hInstance = hInstance;
  282.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  283.     wc.lpfnWndProc = WndProc;
  284.     wc.lpszClassName = className;
  285.     wc.lpszMenuName = NULL;
  286.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  287.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  288.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  289.  
  290.     if (RegisterClassEx(&wc) == 0)
  291.     {
  292.         MessageBox(NULL, L"wc", className, MB_OK);
  293.         return 1;
  294.     }
  295.  
  296.     hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_CLIENTEDGE, className, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, hInstance, 0);
  297.     if (hwnd == NULL)
  298.     {
  299.         MessageBox(NULL, L"hwnd", className, MB_OK);
  300.         return 1;
  301.     }
  302.  
  303.     ShowWindow(hwnd, nCmdShow);
  304.     UpdateWindow(hwnd);
  305.  
  306.     while (GetMessage(&msg, NULL, 0, 0) > 0)
  307.     {
  308.         TranslateMessage(&msg);
  309.         DispatchMessage(&msg);
  310.     }
  311.  
  312.     UnregisterClass(className, hInstance);
  313.  
  314.     return msg.wParam;
  315. }
Advertisement