Facebook
From Piotr Gałka, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 135
  1. #if defined(UNICODE) && !defined(_UNICODE)
  2.     #define _UNICODE
  3. #elif defined(_UNICODE) && !defined(UNICODE)
  4.     #define UNICODE
  5. #endif
  6.  
  7. #include <tchar.h>
  8. #include <windows.h>
  9. #include <string>
  10. #include <windows.h>
  11. #include <iostream>
  12. #include <fstream>
  13.  
  14. using namespace std;
  15.  
  16.  
  17.  
  18. /*  Declare Windows procedure  */
  19. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  20.  
  21. /*  Make the class name into a global variable  */
  22. TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
  23.  
  24.     HWND liczba_1_box;
  25.     HWND liczba_2_box;
  26.     HWND liczba_1;
  27.     HWND liczba_2;
  28.     HWND liczba_3;
  29.     HWND czysc;
  30.     HWND cofnij;
  31.  
  32.     HWND dodawanie;
  33.     HWND odejmowanie;
  34.     HWND mnozenie;
  35.     HWND dzielenie;
  36.     HWND modulo;
  37.  
  38.     HWND op_porownania;
  39.     HWND mniejszy;
  40.     HWND wiekszy;
  41.     HWND rowny;
  42.     HWND rozny;
  43.  
  44.     HWND kolo;
  45.     HWND obwod;
  46.     HWND pole;
  47.  
  48.  
  49.  
  50. int WINAPI WinMain (HINSTANCE hThisInstance,
  51.                      HINSTANCE hPrevInstance,
  52.                      LPSTR lpszArgument,
  53.                      int nCmdShow)
  54. {
  55.     HWND hwnd;
  56.     HWND dane;
  57.     HWND liczba_3_box;
  58.     HWND op_arytm;
  59.     MSG messages;
  60.     WNDCLASSEX wincl;
  61.     /* The Window structure */
  62.     wincl.hInstance = hThisInstance;
  63.     wincl.lpszClassName = szClassName;
  64.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  65.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  66.     wincl.cbSize = sizeof (WNDCLASSEX);
  67.  
  68.     /* Use default icon and mouse-pointer */
  69.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  70.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  71.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  72.     wincl.lpszMenuName = NULL;                 /* No menu */
  73.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  74.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  75.     /* Use Windows's default colour as the background of the window */
  76.     wincl.hbrBackground = CreateSolidBrush(RGB(5, 102, 141));
  77.  
  78.     /* Register the window class, and if it fails quit the program */
  79.     if (!RegisterClassEx (&wincl))
  80.         return 0;
  81.  
  82.     /* The class is registered, let's create the program*/
  83.     hwnd = CreateWindowEx (
  84.            0,
  85.            szClassName,
  86.            _T("Kalkulator PG 1F "),
  87.            WS_OVERLAPPEDWINDOW,
  88.            CW_USEDEFAULT,
  89.            CW_USEDEFAULT,
  90.            700,
  91.            600,
  92.            HWND_DESKTOP,
  93.            NULL,
  94.            hThisInstance,
  95.            NULL     );
  96.     dane = CreateWindowEx(0, "BUTTON", "DANE", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 40, 10, 600, 80, hwnd, NULL, hThisInstance, NULL);
  97.     liczba_1_box = CreateWindowEx(0, "BUTTON", "a", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 50, 30, 100, 50, hwnd, NULL, hThisInstance, NULL);
  98.     liczba_1 = CreateWindowEx(0, "EDIT", "0", WS_CHILD | WS_VISIBLE | ES_RIGHT, 60, 50, 70, 20, hwnd, NULL, hThisInstance, NULL);
  99.     liczba_2 = CreateWindowEx(0, "EDIT", "0", WS_CHILD | WS_VISIBLE | ES_RIGHT, 160, 50, 70, 20, hwnd, NULL, hThisInstance, NULL);
  100.     liczba_2_box = CreateWindowEx(0, "BUTTON", "b", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 150, 30, 100, 50, hwnd, NULL, hThisInstance, NULL);
  101.     liczba_3 = CreateWindowEx(0, "EDIT", "0", WS_CHILD | WS_VISIBLE | ES_RIGHT, 280, 50, 140, 20, hwnd, NULL, hThisInstance, NULL);
  102.     liczba_3_box = CreateWindowEx(0, "BUTTON", "WYNIK", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 260, 30, 180, 50, hwnd, NULL, hThisInstance, NULL);
  103.     czysc = CreateWindowEx(0, "BUTTON", "CZYSC", WS_CHILD | WS_VISIBLE, 480, 25, 140, 60, hwnd, NULL, hThisInstance, NULL);
  104.  
  105.     op_arytm = CreateWindowEx(0, "BUTTON", "ARYTMETYKA", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 40, 100, 200, 430, hwnd, NULL, hThisInstance, NULL);
  106.     dodawanie = CreateWindowEx(0, "BUTTON", "DODAWANIE", WS_CHILD | WS_VISIBLE, 40, 130, 200, 75, hwnd, NULL, hThisInstance, NULL);
  107.     odejmowanie = CreateWindowEx(0, "BUTTON", "ODEJMOWANIE", WS_CHILD | WS_VISIBLE, 40, 205, 200, 75, hwnd, NULL, hThisInstance, NULL);
  108.     mnozenie = CreateWindowEx(0, "BUTTON", "MNO¯ENIE", WS_CHILD | WS_VISIBLE, 40, 280, 200, 75, hwnd, NULL, hThisInstance, NULL);
  109.     dzielenie = CreateWindowEx(0, "BUTTON", "DZIELENIE", WS_CHILD | WS_VISIBLE, 40, 355, 200, 75, hwnd, NULL, hThisInstance, NULL);
  110.     modulo = CreateWindowEx(0, "BUTTON", "DZIELENIE MODULO", WS_CHILD | WS_VISIBLE, 40, 430, 200, 75, hwnd, NULL, hThisInstance, NULL);
  111.  
  112.  
  113.     op_porownania = CreateWindowEx(0, "BUTTON", "PORÓWNANIE", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 400, 100, 200, 430, hwnd, NULL, hThisInstance, NULL);
  114.     mniejszy = CreateWindowEx(0, "BUTTON", "a < b", WS_CHILD | WS_VISIBLE, 400, 120, 200, 100, hwnd, NULL, hThisInstance, NULL);
  115.     wiekszy = CreateWindowEx(0, "BUTTON", " a> b", WS_CHILD | WS_VISIBLE, 400, 220, 200, 100, hwnd, NULL, hThisInstance, NULL);
  116.     rowny = CreateWindowEx(0, "BUTTON", "a == b", WS_CHILD | WS_VISIBLE, 400, 320, 200, 100, hwnd, NULL, hThisInstance, NULL);
  117.     rozny = CreateWindowEx(0, "BUTTON", "a != b", WS_CHILD | WS_VISIBLE, 400, 420, 200, 100, hwnd, NULL, hThisInstance, NULL);
  118.  
  119.  
  120.     kolo = CreateWindowEx(0, "BUTTON", "KOLO (r = a)", WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 245, 100, 150, 430, hwnd, NULL, hThisInstance, NULL);
  121.     obwod = CreateWindowEx(0, "BUTTON", "OBWOD ", WS_CHILD | WS_VISIBLE, 245, 120, 150, 200, hwnd, NULL, hThisInstance, NULL);
  122.     pole = CreateWindowEx(0, "BUTTON", " POLE", WS_CHILD | WS_VISIBLE, 245, 320, 150, 200, hwnd, NULL, hThisInstance, NULL);
  123.  
  124.  
  125.     /* Make the window visible on the screen */
  126.     ShowWindow (hwnd, nCmdShow);
  127.  
  128.     /* Run the message loop. It will run until GetMessage() returns 0 */
  129.     while (GetMessage (&messages, NULL, 0, 0))
  130.     {
  131.         /* Translate virtual-key messages into character messages */
  132.         TranslateMessage(&messages);
  133.         /* Send message to WindowProcedure */
  134.         DispatchMessage(&messages);
  135.     }
  136.  
  137.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  138.     return messages.wParam;
  139. }
  140. double suma(double a, double b){
  141.     return a+b;
  142. }
  143. double odejm(double a, double b){
  144.     return a-b;
  145. }
  146. double mnoz(double a, double b){
  147.     return a*b;
  148. }
  149.  
  150. double dziel(double a, double b){
  151.     if(b == 0){
  152.         return 0;
  153.     }
  154.     else{
  155.         return a/b;
  156.     }
  157. }
  158. int dziel_modulo(int a, int b){
  159.     if(b == 0){
  160.         return 0;
  161.     }
  162.     else{
  163.         return a%b;
  164.     }
  165. }
  166. char mniej(int a, int b){
  167.     if(a < b){
  168.         return 'T';
  169.     }
  170.     else{
  171.         return 'F';
  172.     }
  173. }
  174. char wiek(int a, int b){
  175.     if(a > b){
  176.         return 'T';
  177.     }
  178.     else{
  179.         return 'F';
  180.     }
  181. }
  182. char rown(int a, int b){
  183.     if(a == b){
  184.         return 'T';
  185.     }
  186.     else{
  187.         return 'F';
  188.     }
  189. }
  190. char rozn(int a, int b){
  191.     if(a != b){
  192.         return 'T';
  193.     }
  194.     else{
  195.         return 'F';
  196.     }
  197. }
  198. double Pi = 3.14;
  199. double obw(double r){
  200.     double wynik = 2 * Pi * r;
  201.     return wynik;
  202. }
  203. double pol(double r){
  204.     return Pi * (r * r);
  205. }
  206. void zapis(int a, char z, int b, char c[16]){
  207.     fstream plik;
  208.     plik.open("PiotrGalka_zapis.8", ios::app);
  209.     plik<<a<<""<<z<<""<<b<<"="<<c<<endl;
  210. }
  211. void zapis_kola(string rodzaj, double r, char c[16]){
  212.     fstream plik;
  213.     plik.open("PiotrGalka_zapis.8", ios::app);
  214.     plik<<rodzaj<<":"<<" "<<r<<" = "<<c<<endl;
  215. }
  216.  
  217.  
  218. char txt1[8];
  219. char txt2[8];
  220. char txt3[16];
  221. char wynik[16];
  222. double a,b;
  223. char wynik_porownania[1];
  224.  
  225. /*  This function is called by the Windows function DispatchMessage()  */
  226.  
  227. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  228. {
  229.     switch (message)                  /* handle the messages */
  230.     {
  231.         case WM_DESTROY:
  232.             PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
  233.             break;
  234.         case WM_COMMAND:
  235.             if ((HWND) lParam == czysc){
  236.                 SetWindowText(liczba_1, "0");
  237.                 SetWindowText(liczba_2, "0");
  238.                 SetWindowText(liczba_3, "0");
  239.             }
  240.             else if(( HWND ) lParam == dodawanie){
  241.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  242.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  243.                 a = atof(txt1); b = atof(txt2);
  244.                 sprintf(wynik, "%f", suma(a,b));
  245.                 SetWindowText(liczba_3, wynik);
  246.                 zapis(a,'+',b,wynik);
  247.             }
  248.             else if ((HWND) lParam == odejmowanie){
  249.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  250.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  251.                 a = atoi(txt1); b = atoi(txt2);
  252.                 sprintf(wynik, "%f", odejm(a,b));
  253.                 SetWindowText(liczba_3, wynik);
  254.                 zapis(a,'-',b,wynik);
  255.             }
  256.             else if ((HWND) lParam == mnozenie){
  257.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  258.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  259.                 a = atoi(txt1); b = atoi(txt2);
  260.                 sprintf(wynik, "%f", mnoz(a,b));
  261.                 SetWindowText(liczba_3, wynik);
  262.                 zapis(a,'*',b,wynik);
  263.             }
  264.             else if ((HWND) lParam == dzielenie){
  265.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  266.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  267.                 a = atof(txt1); b = atof(txt2);
  268.                 sprintf(wynik, "%f", dziel(a,b));
  269.                 SetWindowText(liczba_3, wynik);
  270.                 zapis(a,'/',b,wynik);
  271.             }
  272.             else if ((HWND) lParam == modulo){
  273.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  274.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  275.                 a = atoi(txt1); b = atoi(txt2);
  276.                 wsprintf(wynik, "%d", dziel_modulo(a,b));
  277.                 SetWindowText(liczba_3, wynik);
  278.                 zapis(a,'-',b,wynik);
  279.             }
  280.             else if ((HWND) lParam == obwod){
  281.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  282.                 a = atof(txt1);
  283.                 sprintf(wynik, "%f", obw(a));
  284.                 SetWindowText(liczba_3, wynik);
  285.                 zapis_kola("Obwód z",a,wynik);
  286.             }
  287.             else if ((HWND) lParam == pole){
  288.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  289.                 a = atof(txt1);
  290.                 sprintf(wynik, "%f", pol(a));
  291.                 SetWindowText(liczba_3, wynik);
  292.                 zapis_kola("Pole z",a,wynik);
  293.             }
  294.             else if ((HWND) lParam == mniejszy){
  295.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  296.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  297.                 a = atoi(txt1);
  298.                 b = atoi(txt2);
  299.                 wsprintf(wynik, "%d", mniej(a,b));
  300.                 wynik_porownania[0] = mniej(a,b);
  301.                 SetWindowText(liczba_3, wynik_porownania);
  302.                 zapis(a,'>',b,wynik_porownania);
  303.             }
  304.             else if ((HWND) lParam == wiekszy){
  305.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  306.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  307.                 a = atoi(txt1); b = atoi(txt2);
  308.                 wsprintf(wynik, "%d", wiek(a,b));
  309.                 wynik_porownania[0] = wiek(a,b);
  310.                 SetWindowText(liczba_3, wynik_porownania);
  311.                 zapis(a,'<',b,wynik_porownania);
  312.             }
  313.             else if ((HWND) lParam == rowny){
  314.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  315.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  316.                 a = atoi(txt1); b = atoi(txt2);
  317.                 wsprintf(wynik, "%d", wiek(a,b));
  318.                 wynik_porownania[0] = rown(a,b);
  319.                 SetWindowText(liczba_3, wynik_porownania);
  320.                 zapis(a,'=',b,wynik_porownania);
  321.             }
  322.             else if ((HWND) lParam == rozny){
  323.                 GetWindowText(liczba_1, txt1, sizeof(txt1));
  324.                 GetWindowText(liczba_2, txt2, sizeof(txt2));
  325.                 a = atoi(txt1); b = atoi(txt2);
  326.                 wsprintf(wynik, "%d", wiek(a,b));
  327.                 wynik_porownania[0] = rozn(a,b);
  328.                 SetWindowText(liczba_3, wynik_porownania);
  329.                 zapis(a,'!',b,wynik_porownania);
  330.             }
  331.  
  332.             break;
  333.         default:                      /* for messages that we don't deal with */
  334.             return DefWindowProc (hwnd, message, wParam, lParam);
  335.     }
  336.  
  337.     return 0;
  338. }
  339.