Hyluss icon

zbulwiony calc

Hyluss | PRO | 11/29/16 08:10:52 PM UTC | 0 ⭐ | 10322 👁️ | Never ⏰ | []
C++ (WinAPI) |

0 B

|

None

|

0 👍

/

0 👎

#define SCREEN_WIDTH 700
#define SCREEN_HEIGHT 600
 
#define ID_BUTTON1 1
#define ID_BUTTON2 2
#define ID_BUTTON3 3
#define ID_BUTTON4 4
#define ID_BUTTON5 5
#define ID_BUTTON6 6
#define ID_BUTTON7 7
#define ID_BUTTON8 8
#define ID_BUTTON9 9
#define ID_BUTTON0 0
 
#define ID_PLUS 11
#define ID_MINUS 12
#define ID_MNOZENIE 13
#define ID_DZIELENIE 14
#define ID_PRZECINEK 15
#define ID_ROWNASIE 16
 
#define ID_VALUEFIELD1 400
 
#include <windows.h>
#include <tchar.h>
 
TCHAR className[] = TEXT("NazwaKlasy");
TCHAR appName[] = TEXT("Stoperan");
 
HWND hwnd;
MSG msg;
 
 
 
 
 
/*
void Przelicz(HWND hwnd)
{
    DWORD dl = (GetWindowTextLength (poletekstowe));
    wchar_t Bufor[128];
    GetWindowTextW (poletekstowe, Bufor , dl+1);
    double value = _wtof (Bufor); // konwersja tekstu na liczbe
 
    if (BST_CHECKED == IsDlgButtonChecked (hwnd, CM_NA_CALE)) 
    {
        value = value / 2.5;
    }
    else
    {
        value = value * 2.5;
    }
    _swprintf (Bufor,L"%.2f",value); // wczytanie do bufora wartosci value
    SetWindowTextW  (statik,Bufor);
}
*/
 
wchar_t Bufor[100];
int liczba=0;
 
void Wpisz (HWND &ValueField, char* znak)
{   //ValueField
    DWORD dl = (GetWindowTextLength (ValueField));
    
    if (znak == "0" || znak=="1" || znak=="2" || znak=="3" || znak=="4" || znak=="5" || znak=="6" || znak=="7" || znak=="8" || znak=="9")
    {
        int value = atof (znak);
        _swprintf (&Bufor[dl],L"%d",value);
        SetWindowText  (ValueField,Bufor);
    }
    else
    {
        if (znak == "+")
        {   
            _swprintf (&Bufor[dl],L"+");
            SetWindowText  (ValueField,Bufor);
        }
    }
}
 
 
void Rozwiaz ( HWND &ValueField)
{
    DWORD dl = (GetWindowTextLength (ValueField));
    wchar_t Wynik[128];
    GetWindowTextW (ValueField, Wynik , dl+1);
    double value = _wtof (Wynik); // konwersja tekstu na liczbe
}
 
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static RECT R;
    static HWND ValueField, BUTTON3, BUTTON2, BUTTON1,BUTTON4,BUTTON5,BUTTON6,BUTTON7,BUTTON8,BUTTON9,BUTTON0, DODAJ, ODEJMIJ, POMNOZ, PODZIEL, ROWNASIE;
 
    switch (msg)
    {
        case WM_CREATE:
        {
             HINSTANCE &hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
 
             ValueField = CreateWindowEx (0,L"STATIC",NULL,WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_VALUEFIELD1, hInstance,0);
             if (ValueField==0)
             {
                 MessageBox (hwnd,L"Problem z ValueField", className, MB_OK);
                 return 1;
             }
    
             BUTTON1 = CreateWindowEx (0,L"BUTTON",L"1",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON1, hInstance,0);
             if (!BUTTON1)
             {
                 MessageBox (hwnd,L"Problem z BUTTON1", className, MB_OK);
                 return 1;
             }
 
             BUTTON2 = CreateWindowEx (0,L"BUTTON",L"2",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON2, hInstance,0);
             if (!BUTTON2)
             {
                 MessageBox (hwnd,L"Problem z BUTTON2", className, MB_OK);
                 return 1;
             }
 
             BUTTON3 = CreateWindowEx (0,L"BUTTON",L"3",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON3, hInstance,0);
             if (!BUTTON3)
             {
                 MessageBox (hwnd,L"Problem z BUTTON3", className, MB_OK);
                 return 1;
             }
 
             BUTTON4 = CreateWindowEx (0,L"BUTTON",L"Start",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON4, hInstance,0);
             if (!BUTTON4)
             {
                 MessageBox (hwnd,L"Problem z BUTTON4", className, MB_OK);
                 return 1;
             }
 
             BUTTON5 = CreateWindowEx (0,L"BUTTON",L"Stop",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON5, hInstance,0);
             if (!BUTTON5)
             {
                 MessageBox (hwnd,L"Problem z BUTTON5", className, MB_OK);
                 return 1;
             }
 
             BUTTON6 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON6, hInstance,0);
             if (!BUTTON6)
             {
                 MessageBox (hwnd,L"Problem z BUTTON6", className, MB_OK);
                 return 1;
             }
 
 
             BUTTON7 = CreateWindowEx (0,L"BUTTON",L"Start",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON7, hInstance,0);
             if (!BUTTON7)
             {
                 MessageBox (hwnd,L"Problem z BUTTON7", className, MB_OK);
                 return 1;
             }
 
             BUTTON8 = CreateWindowEx (0,L"BUTTON",L"Stop",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON8, hInstance,0);
             if (!BUTTON8)
             {
                 MessageBox (hwnd,L"Problem z BUTTON8", className, MB_OK);
                 return 1;
             }
 
             BUTTON9 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON9, hInstance,0);
             if (!BUTTON9)
             {
                 MessageBox (hwnd,L"Problem z BUTTON9", className, MB_OK);
                 return 1;
             }
 
             BUTTON0 = CreateWindowEx (0,L"BUTTON",L"Resetuj",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_BUTTON0, hInstance,0);
             if (!BUTTON0)
             {
                 MessageBox (hwnd,L"Problem z BUTTON0", className, MB_OK);
                 return 1;
             }
 
             DODAJ = CreateWindowEx (0,L"BUTTON",L"Dodaj +",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_PLUS, hInstance,0);
             if (!DODAJ)
             {
                 MessageBox (hwnd,L"Problem z DODAJ", className, MB_OK);
                 return 1;
             }
 
             ODEJMIJ = CreateWindowEx (0,L"BUTTON",L"ODEJMIJ -",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_MINUS, hInstance,0);
             if (!ODEJMIJ)
             {
                 MessageBox (hwnd,L"Problem z ODEJMIJ", className, MB_OK);
                 return 1;
             }
 
             POMNOZ = CreateWindowEx (0,L"BUTTON",L"POMNOZ x",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_MNOZENIE, hInstance,0);
             if (!POMNOZ)
             {
                 MessageBox (hwnd,L"Problem z POMNOZ", className, MB_OK);
                 return 1;
             }
 
             PODZIEL = CreateWindowEx (0,L"BUTTON",L"PODZIEL /",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_DZIELENIE, hInstance,0);
             if (!PODZIEL)
             {
                 MessageBox (hwnd,L"Problem z PODZIEL", className, MB_OK);
                 return 1;
             }
 
             ROWNASIE = CreateWindowEx (0,L"BUTTON",L"ROWNA SIE =",WS_CHILD | WS_VISIBLE, 0, 0 , 0 ,0, hwnd, (HMENU)ID_ROWNASIE, hInstance,0);
             if (!ROWNASIE)
             {
                 MessageBox (hwnd,L"Problem z ROWNASIE", className, MB_OK);
                 return 1;
             }
 
        }break;
 
        case WM_SIZE:
            {
            GetClientRect(hwnd, &R);         
            MoveWindow(ValueField, R.right / 3, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
            MoveWindow(BUTTON1, R.right / 3, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
            MoveWindow(BUTTON2, R.right / 2, R.bottom / 2.5 + 10, R.right / 7, R.bottom / 15, 1);
            MoveWindow(BUTTON3, R.right / 2, R.bottom / 3, R.right / 7, R.bottom / 15, 1);
            MoveWindow(ROWNASIE,  R.right / 3, R.bottom / 2.5 + 60, R.right / 7, R.bottom / 15, 1);
            MoveWindow(DODAJ,  R.right / 2, R.bottom / 2.5 + 60, R.right / 7, R.bottom / 15, 1);
            }break;
 
        case WM_GETMINMAXINFO:
            ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 550;
            ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 400;
            ((MINMAXINFO*)lParam)->ptMaxTrackSize.x = 1000;
            ((MINMAXINFO*)lParam)->ptMaxTrackSize.y = 900;
            break;
 
        case WM_COMMAND:
            switch (wParam)
            {
                case ID_BUTTON1:
                    Wpisz (ValueField, "1");
                    break;
 
                case ID_BUTTON2:
                     Wpisz (ValueField, "2");
                    break;
 
                case ID_BUTTON3:
                     Wpisz (ValueField, "3");
                    break;
 
                case ID_PLUS:
                     Wpisz (ValueField, "+");
                     break;
 
                case ID_ROWNASIE:
                    SetWindowText (ValueField,L"Sam se kurwa policz");
                    break;
 
            }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 lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = className;
    wc.lpszMenuName = NULL;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
 
    if (RegisterClassEx(&wc) == 0)
    {
        MessageBox(NULL, L"wc", className, MB_OK);
        return 1;
    }
 
    hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_CLIENTEDGE, className, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, hInstance, 0);
    if (hwnd == NULL)
    {
        MessageBox(NULL, L"hwnd", className, MB_OK);
        return 1;
    }
 
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
 
    while (GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
 
    UnregisterClass(className, hInstance);
 
    return msg.wParam;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎