Programmieren - alles kontrollieren 4.941 Themen, 20.715 Beiträge

Taschenrechner in C programmieren

BleedingSoul / 0 Antworten / Baumansicht Nickles

Hallo!


Ich will mir in C einen grafischen Taschenrechner programmieren. Das Fenstergerüst mit Buttons und Editfeldern hab ich schon. Ich will zwei Zahlen in zwei Editfelder eingeben und wenn ich dann auf den entsprechenden Button drücke soll das Ergebnis in einem dritten Editfeld stehen.


Ich weiss aber nicht wie ich eine Zahl aus dem Editfeld lesen kann. Die Tuts die ich mit google gefunden habe beschreiben nur wie man ein Zeichen aus dem Feld liest.


Hat jemand eine Idee wie ich das hinkriegen könnte?


mfg BleedingSoul


Hier der Source, den ich bisher hab:


#include <windows.h>


LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR nCmdLine, int nCmdShow)
{


 HWND hwnd;
 WNDCLASS wcl;
 MSG msg;
 char szName[]  = "Fensterklasse";
 HBRUSH MyBrush = CreateSolidBrush ( RGB (50, 0, 150) );


 wcl.cbClsExtra   = 0;
 wcl.cbWndExtra   = 0;
 wcl.hbrBackground  = MyBrush;
 wcl.hCursor    = 0;
 wcl.hIcon    = LoadIcon (NULL, IDI_APPLICATION);
 wcl.hInstance   = hInstance;
 wcl.lpfnWndProc   = WndProc;
 wcl.lpszClassName  = szName;
 wcl.lpszMenuName  = NULL;
 wcl.style    = 0;


 RegisterClass (&wcl);


 hwnd = CreateWindow (szName, "Taschenrechner", WS_OVERLAPPEDWINDOW, 300, 100, 600, 600,
        NULL, NULL, hInstance, NULL);
 
 ShowWindow   (hwnd, nCmdShow);
 UpdateWindow (hwnd);


 while (GetMessage (&msg, NULL, 0, 0))
 {
  TranslateMessage (&msg);
  DispatchMessage  (&msg);
 }
 
 return msg.wParam;
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 
  static HWND hwndButton1;
  static HWND hwndButton2;
  static HWND hwndButton3;
  static HWND hwndButton4;
  static HWND hwndButton5;
  static HWND hwndButton6;
  static HWND hwndButton7;
  static HWND hwndButton8;
  static HWND hwndButton9;
  static HWND hwndButton10;
  static HWND hwndedit1;
  static HWND hwndedit2;
  static HWND hwndedit3;


 switch (message)
 {


 case WM_CREATE:


  hwndButton1 = CreateWindow ( "button", "Addieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        100, 200, 100, 40, hwnd, (HMENU)1,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndButton2 = CreateWindow ( "button", "Subtrahieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        400, 200, 100, 40, hwnd, (HMENU)2,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
        
  hwndButton3 = CreateWindow ( "button", "Multiplizieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        100, 250, 100, 40, hwnd, (HMENU)3,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
        
  hwndButton4 = CreateWindow ( "button", "Dividieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        400, 250, 100, 40, hwnd, (HMENU)4,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndButton5 = CreateWindow ( "button", "Wurzel", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        400, 300, 100, 40, hwnd, (HMENU)5,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndButton6 = CreateWindow ( "button", "Quadrieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        100, 300, 100, 40, hwnd, (HMENU)6,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndButton7 = CreateWindow ( "button", "Sinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        110, 400, 75, 20, hwnd, (HMENU)7,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
        
  hwndButton8 = CreateWindow ( "button", "Cosinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        210, 400, 75, 20, hwnd, (HMENU)8,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
        
  hwndButton9 = CreateWindow ( "button", "Tangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        310, 400, 75, 20, hwnd, (HMENU)9,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndButton10 = CreateWindow ( "button", "Cotangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
        410, 400, 75, 20, hwnd, (HMENU)10,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndedit1   = CreateWindow ( "edit", "Zahl1", WS_CHILD | WS_VISIBLE,
        150, 100, 100, 30, hwnd, (HMENU)5,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


  hwndedit2   = CreateWindow ( "edit", "Zahl2", WS_CHILD | WS_VISIBLE,
        350, 100, 100, 30, hwnd, (HMENU)6,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
  
  hwndedit3 = CreateWindow ( "edit", "Ergebnis", WS_CHILD | WS_VISIBLE,
        230, 500, 150, 40, hwnd, (HMENU)7,
        (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
 
  return 0;
     
 case WM_COMMAND:


    
  return 0; 
  
  case WM_DESTROY:
      PostQuitMessage (0);
   return 0;


 }


 return DefWindowProc (hwnd, message, wParam, lParam);



 

bei Antwort benachrichtigen