Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Kalkulator na okienkach WinApi

Ostatnio zmodyfikowano 2009-05-30 11:43
Autor Wiadomość
Macius700
Temat założony przez niniejszego użytkownika
Kalkulator na okienkach WinApi
» 2009-05-28 21:11:49
C/C++
#include <windows.h>

LPSTR NazwaKlasy = "Klasa Okienka";
MSG Komunikat;
HWND g_hPrzycisk1, g_hPrzycisk2, g_hPrzycisk3, g_hPrzycisk4, g_hPrzycisk5, g_hPrzycisk6, g_hPrzycisk7, g_hPrzycisk8, g_hPrzycisk9, g_hPrzycisk10, g_hPrzycisk11, g_hPrzycisk12, g_hPrzycisk13, g_hPrzycisk14, g_hPrzycisk15, g_hPrzycisk16, hText;
char * szText;

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
   
    //WYPEŁNIANIE STRUKTURY
    WNDCLASSEX wc;
   
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = NazwaKlasy;
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
   
    //REJESTROWANIE KLASY OKNA
    if( !RegisterClassEx( & wc ) )
    {
        MessageBox( NULL, "Wysoka Komisja odmawia rejestracji tego okna!", "Niestety...", MB_ICONEXCLAMATION | MB_OK );
        return 1;
    }
   
    //TWORZENIE OKNA
    HWND hwnd;
   
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, "Oto okienko", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, NULL, NULL, hInstance, NULL );
    g_hPrzycisk1 = CreateWindowEx( 0, "BUTTON", "7", WS_CHILD | WS_VISIBLE, 100, 100, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk2 = CreateWindowEx( 0, "BUTTON", "4", WS_CHILD | WS_VISIBLE, 100, 140, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk3 = CreateWindowEx( 0, "BUTTON", "1", WS_CHILD | WS_VISIBLE, 100, 180, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk4 = CreateWindowEx( 0, "BUTTON", "8", WS_CHILD | WS_VISIBLE, 140, 100, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk5 = CreateWindowEx( 0, "BUTTON", "5", WS_CHILD | WS_VISIBLE, 140, 140, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk6 = CreateWindowEx( 0, "BUTTON", "2", WS_CHILD | WS_VISIBLE, 140, 180, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk7 = CreateWindowEx( 0, "BUTTON", "9", WS_CHILD | WS_VISIBLE, 180, 100, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk8 = CreateWindowEx( 0, "BUTTON", "6", WS_CHILD | WS_VISIBLE, 180, 140, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk9 = CreateWindowEx( 0, "BUTTON", "3", WS_CHILD | WS_VISIBLE, 180, 180, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk10 = CreateWindowEx( 0, "BUTTON", "+", WS_CHILD | WS_VISIBLE, 220, 60, 40, 120, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk11 = CreateWindowEx( 0, "BUTTON", "=", WS_CHILD | WS_VISIBLE, 220, 180, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk12 = CreateWindowEx( 0, "BUTTON", "/", WS_CHILD | WS_VISIBLE, 100, 60, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk13 = CreateWindowEx( 0, "BUTTON", "*", WS_CHILD | WS_VISIBLE, 140, 60, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk14 = CreateWindowEx( 0, "BUTTON", "-", WS_CHILD | WS_VISIBLE, 180, 60, 40, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk15 = CreateWindowEx( 0, "BUTTON", "0", WS_CHILD | WS_VISIBLE, 100, 220, 80, 40, hwnd, NULL, hInstance, NULL );
    g_hPrzycisk16 = CreateWindowEx( 0, "BUTTON", "Del", WS_CHILD | WS_VISIBLE, 180, 220, 80, 40, hwnd, NULL, hInstance, NULL );
   
   
   
    hText = CreateWindowEx( WS_EX_CLIENTEDGE, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 100, 10, 160, 50, hwnd, NULL, hInstance, NULL );
    SetWindowText( hText, "" );
   
    if( hwnd == NULL )
    {
        MessageBox( NULL, "Okno odmówiło przyjścia na świat!", "Ale kicha...", MB_ICONEXCLAMATION );
        return 1;
    }
   
    ShowWindow( hwnd, nCmdShow ); //Pokaż okienko...
    UpdateWindow( hwnd );
   
    //Pętla komunikatów
    while( GetMessage( & Komunikat, NULL, 0, 0 ) )
    {
        TranslateMessage( & Komunikat );
        DispatchMessage( & Komunikat );
    }
    return Komunikat.wParam;
}

//OBSŁUGA ZDARZEŃ
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
    case WM_COMMAND:
        if(( HWND ) lParam == g_hPrzycisk1 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            int nTextLenght =( int ) SendMessage( hText, WM_GETTEXTLENGTH, 0, 0 );
            SendMessage( hText, EM_SETSEL, nTextLenght, nTextLenght );
            szText = "7";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk2 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "4";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
       
        if(( HWND ) lParam == g_hPrzycisk3 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "1";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk4 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "8";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk5 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "5";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk6 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "2";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk7 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "9";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk8 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "6";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk9 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "3";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk10 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "+";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk11 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "=";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk12 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "/";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk13 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "*";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk14 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "-";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk15 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = "0";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
        if(( HWND ) lParam == g_hPrzycisk16 )
        { //MessageBox(hwnd, "Nacisnąłeś przycisk!", "Ha!", MB_ICONINFORMATION);
            //int nTextLenght = (int) SendMessage(hText, WM_GETTEXTLENGTH, 0, 0);
            //SendMessage(hText, EM_SETSEL, nTextLenght, nTextLenght);
            szText = " ";
            SendMessage( hText, EM_REPLACESEL, 0,( LPARAM ) szText );
        }
       
       
       
        break;
    case WM_CLOSE:
        DestroyWindow( hwnd );
        break;
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;
        default:
        return DefWindowProc( hwnd, msg, wParam, lParam );
    }
    return 0;
}


Zrobiłem taki kalkualtor  wszytsko mi działa oprocz wykonywania działań np wcisne 2+2=.... i powinno mi pokazać 4 jak to zrobic? i jak zrobic kasowania jednego wciśnietego elemntu jesli ancisneimy Del??

Moze ktos mi napisać jaka napisać formułe dla dodawania
i jak zrtobic zeby element sie usuwał jesli nacisniemy Del
Reszte dam sobie rade
P-7235
DejaVu
» 2009-05-28 21:20:57
Dostałeś we wcześniejszym temacie kurs winapi. Jeśli nie potrafisz czytać ze zrozumieniem materiałów, które dostałeś to sorry ale programowanie nie jest dla Ciebie. Mówisz, że zrobiłeś kalkulator. Co po kalkulatorze, który nawet nie potrafi dodawać? De'facto nic nie zrobiłeś i jak zwykle czekasz aż ktoś Ci da rozwiązanie. Twoja postawa drażni mnie, ponieważ nie przychodzisz po naukę lecz po rozwiązania.
P-7236
Macius700
Temat założony przez niniejszego użytkownika
» 2009-05-28 21:34:09
dobra zaraz poczytam ten kurs ale nie wiem czy mi sie uda to zrobić
P-7237
lynx
» 2009-05-28 21:52:34
No to skoro nie wiesz czy Ci się uda zrozumieć co tam jest napisane to może zaczniesz uczyć się od początku a nie od WinApi. Bo albo masz duże braki albo małe chęci albo szukasz tylko gotowców.
P-7238
Macius700
Temat założony przez niniejszego użytkownika
» 2009-05-29 12:01:14
Czytałem nie wiem jak to zrobic Prosze powiedzieć co mam napisac
P-7249
DejaVu
» 2009-05-29 12:52:53
:) więc przeczytaj jeszcze raz :)
P-7250
pekfos
» 2009-05-29 18:53:08
ile ogólnie napisałeś programów? jeśli mniej niż 20 to nie ma co
mówić o doświadczeniu.
P-7260
Macius700
Temat założony przez niniejszego użytkownika
» 2009-05-29 21:47:31
Może ktoś mi powiedzieć jak zrobić że jak dam 2+2= to żeby mi pokazało wyniki bo nie czaje tego winapi reszta bedzie analogicznie wieć Prosze o pomoc
P-7277
« 1 » 2
  Strona 1 z 2 Następna strona