[winapi] Kalkulator nie podaje wyników

0

Witam. Robię kalkulator pod Windows i robię i jakoś skończyć nie mogę po zawsze coś nie tak:(
Chciałbym abyście poprawili ten kod w miarę możliwości i objaśnili.

#include <windows.h>
#include<string>
#define mnoz 1000
#define dzie 1001
#define odej 1002
#define dodaj 1003
using namespace std;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HWND klik1,klik2,klik3,klik4,klik5,klik6,klik7,klik8,klik9,edit;
HWND mno,dziel,raz,od,dod,row,kas;
int dzialanie;
HINSTANCE *wsk;

float liczba,liczba1,liczba2,liczba3,liczba4,liczba5,liczba6,liczba7,liczba8,liczba9,wynik;
char wyn[10];

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{wsk=&hThisInstance;
    HWND hwnd;               
    MSG messages;           
    WNDCLASSEX wincl;        

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_BORDER, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           300,                 /* The programs width */
           400,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
           case WM_CREATE:
                
                
   klik1=CreateWindowEx(0,"BUTTON","1",WS_CHILD|WS_VISIBLE,25,60,70,60,hwnd,(HMENU)1,*wsk,NULL);
   klik2=CreateWindowEx(0,"BUTTON","2",WS_CHILD|WS_VISIBLE,110,60,70,60,hwnd,(HMENU)2,*wsk,NULL);       
   klik3=CreateWindowEx(0,"BUTTON","3",WS_CHILD|WS_VISIBLE,195,60,70,60,hwnd,(HMENU)3,*wsk,NULL);
   klik4=CreateWindowEx(0,"BUTTON","4",WS_CHILD|WS_VISIBLE,25,135,70,60,hwnd,(HMENU)4,*wsk,NULL);
   klik5=CreateWindowEx(0,"BUTTON","5",WS_CHILD|WS_VISIBLE,110,135,70,60,hwnd,(HMENU)5,*wsk,NULL);
   klik6=CreateWindowEx(0,"BUTTON","6",WS_CHILD|WS_VISIBLE,195,135,70,60,hwnd,(HMENU)6,*wsk,NULL);
   klik7=CreateWindowEx(0,"BUTTON","7",WS_CHILD|WS_VISIBLE,25,210,70,60,hwnd,(HMENU)7,*wsk,NULL);
   klik8=CreateWindowEx(0,"BUTTON","8",WS_CHILD|WS_VISIBLE,110,210,70,60,hwnd,(HMENU)8,*wsk,NULL);       
   klik9=CreateWindowEx(0,"BUTTON","9",WS_CHILD|WS_VISIBLE,195,210,70,60,hwnd,(HMENU)9,*wsk,NULL);
  //99999999999999999999999999999999999999999999999999999999999999999999999999999999999
   dod=CreateWindowEx(0,"BUTTON","+",WS_CHILD|WS_VISIBLE,70,285,30,30,hwnd,(HMENU)10,*wsk,NULL);
   od=CreateWindowEx(0,"BUTTON","-",WS_CHILD|WS_VISIBLE,120,285,30,30,hwnd,(HMENU)11,*wsk,NULL);
   dziel=CreateWindowEx(0,"BUTTON","/",WS_CHILD|WS_VISIBLE,170,285,30,30,hwnd,(HMENU)12,*wsk,NULL);
   mno=CreateWindowEx(0,"BUTTON","*",WS_CHILD|WS_VISIBLE,220,285,30,30,hwnd,(HMENU)13,*wsk,NULL);       
  //99999999999999999999999999999999999999999999999999999999999999999999999999999999999999990
  row=CreateWindowEx(0,"BUTTON","=",WS_CHILD|WS_VISIBLE,145,325,95,40,hwnd,(HMENU)14,*wsk,NULL);
  kas=CreateWindowEx(0,"BUTTON","C",WS_CHILD|WS_VISIBLE,60,325,60,40,hwnd,(HMENU)15,*wsk,NULL);
   //00000000000000000000000000000000000000000000000000000000000000000000000000000000
   edit=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE,10,10,270,35,hwnd,NULL,*wsk,NULL);   
        break;
        //----------------------------------------------------------------------------
        case WM_COMMAND:
          
             switch(wParam)
{
                       case 1:
                            {
                             
                                
                            
        SetWindowText(edit,"1");
      DWORD dl1;
      dl1 = GetWindowTextLength(edit);
      LPSTR bf1= (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl1 + 1);
      GetWindowText(edit, bf1, dl1 + 1);
      liczba = atof(bf1); 
 
       
                           }
                  break;
                     case 2:
                  {
             SetWindowText(edit,"2");
      DWORD dl2;
      dl2 = GetWindowTextLength(edit);
      LPSTR bf2 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl2 + 1);
      GetWindowText(edit, bf2, dl2 + 1);
      liczba= atof(bf2);     
                       } 
                          break;
                  case 3:
                   {
                  SetWindowText(edit,"3");
      DWORD dl3;
      dl3 = GetWindowTextLength(edit);
      LPSTR bf3 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl3 + 1);
      GetWindowText(edit, bf3, dl3 + 1);
      liczba = atof(bf3); 
                                }
                                break;
                           case 4:
                   {
                  SetWindowText(edit,"4");
      DWORD dl4;
      dl4 = GetWindowTextLength(edit);
      LPSTR bf4 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl4 + 1);
      GetWindowText(edit, bf4, dl4 + 1);
      liczba = atof(bf4); 
                                }
                                break;
                   case 5:
                   {
                  SetWindowText(edit,"5");
      DWORD dl5;
      dl5 = GetWindowTextLength(edit);
      LPSTR bf5 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl5 + 1);
      GetWindowText(edit, bf5, dl5 + 1);
      liczba = atof(bf5); 
                                }
                                break;
             
              case 6:
                   {
                  SetWindowText(edit,"6");
      DWORD dl6;
      dl6 = GetWindowTextLength(edit);
      LPSTR bf6 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl6 + 1);
      GetWindowText(edit, bf6, dl6 + 1);
      liczba = atof(bf6); 
                                }
                                break;
              case 7:
                   {
                  SetWindowText(edit,"7");
      DWORD dl7;
      dl7 = GetWindowTextLength(edit);
      LPSTR bf7 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl7 + 1);
      GetWindowText(edit, bf7, dl7 + 1);
      liczba = atof(bf7); 
                                }
                                break;
             
             
              case 8:
                   {
                  SetWindowText(edit,"8");
      DWORD dl8;
      dl8 = GetWindowTextLength(edit);
      LPSTR bf8 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl8 + 1);
      GetWindowText(edit, bf8, dl8 + 1);
      liczba = atof(bf8); 
                                }
                                break;
             
              case 9:
                   {
                  SetWindowText(edit,"9");
      DWORD dl9;
      dl9 = GetWindowTextLength(edit);
      LPSTR bf9 = (LPSTR)HeapAlloc(GetProcessHeap(), 0x1 | 0x8, dl9 + 1);
      GetWindowText(edit, bf9, dl9 + 1);
      liczba = atof(bf9); 
                                }
                                break;
                                
                                
                                
 
                                
                                
                                case 10:
                                     dzialanie=dodaj;break;
                               case 11:
                                    dzialanie=odej;break;
                                    case 12:
                                         //if(!liczba)
// MessageBox(hwnd, "dzielenie przez zero", "Error", MB_OK);
    //  else
      
                                         dzialanie=dzie; break;
                                    case 13:
                                         dzialanie=mnoz; break;
                                         case 14:
                                               switch(dzialanie)
                                               {    case dodaj:
                                                            wynik=liczba+liczba;break;
                                                            case odej:
                                                                 wynik=liczba-liczba;break;
                                                                 case dzie:
                                                                      wynik=liczba/liczba;break;
                                                                      case mnoz:
                                                                           wynik=wynik*liczba;break;
                                                                           }
                                                                                                                wsprintf(wyn, "%.d", wynik);
      SetWindowText(edit,wyn); break;    
                                                                           
                                                                
                                              
                                              
     
 
                                     
                                     
                                     
 //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;                             
}

          break;   
             
             
             //--------------------------------------------------------------------
            case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

z góry naprawdę dziękuje i pozdrawiam.

0

Czy nikt nie wie jak to poprawić??

0

Po tym widać, że program w WinAPI to draga przez mękę.

1 użytkowników online, w tym zalogowanych: 0, gości: 1