hallo, ich hoffe mir kann jemand mit meinem Taschenrechner helfen ist bishen viel code aber vielleicht kann sich mal jemand das ansehen. Der Taschenrechner will einfach nicht rechnen.
Danke für die Hilfe schon mal im vorraus
Code:
/*-----------------------------------------------------------------------
Taschenrechner
-----------------------------------------------------------------------*/
#include <windows.h>
#include <cstring>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Taschenrechner") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass);
hwnd = CreateWindow (szAppName, // Name der Fensterklasse
TEXT ("Taschenrechner"), // Fenstertitel
WS_OVERLAPPEDWINDOW, // Fensterstil
300, // X-Position des Fensters
300, // Y-Position des Fensters
300, // Fensterbreite
300, // Fensterhöhe
NULL, // übergeordnetes Fenster
NULL, // Menü
hInstance, // Programm-Kopiezähler (Programm-ID)
NULL) ; // zusätzliche Parameter
ShowWindow (hwnd, iCmdShow) ;
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 char zeichen[0], anzeige[20];
static HWND Button[14], Edit;
static int iErgebnis, iZahl_eins, iZahl_zwei ;
switch (message)
{
case WM_CREATE:
{
for (int i = 0; i < 10; i++)
{
ltoa (i, zeichen, 10);
Button[i] = CreateWindow( "button",
zeichen,
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
}
Button[10] = CreateWindow( "button",
"+",
WS_CHILD | WS_VISIBLE,
0,0,0,0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
Button[11] = CreateWindow( "button",
"-",
WS_CHILD | WS_VISIBLE,
0,0,0,0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
Button[12] = CreateWindow( "button",
"*",
WS_CHILD | WS_VISIBLE,
0,0,0,0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
Button[13] = CreateWindow( "button",
"/",
WS_CHILD | WS_VISIBLE,
0,0,0,0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
Button[14] = CreateWindow( "button",
"=",
WS_CHILD | WS_VISIBLE,
0,0,0,0,
hWnd,
NULL,
((LPCREATESTRUCT) lParam) -> hInstance,
NULL);
Edit = CreateWindow (TEXT ("edit"), anzeige,
WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_RIGHT | ES_AUTOHSCROLL ,
0, 0, 0, 0, hWnd, (HMENU) 1,
((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
return 0;
}
case WM_SIZE:
{
MoveWindow(Button[1], 20, 50, 40, 30, true);
MoveWindow(Button[2], 80, 50, 40, 30, true);
MoveWindow(Button[3], 140, 50, 40, 30, true);
MoveWindow(Button[4], 20, 100, 40, 30, true);
MoveWindow(Button[5], 80, 100, 40, 30, true);
MoveWindow(Button[6], 140, 100, 40, 30, true);
MoveWindow(Button[7], 20, 150, 40, 30, true);
MoveWindow(Button[8], 80, 150, 40, 30, true);
MoveWindow(Button[9], 140, 150, 40, 30, true);
MoveWindow(Button[0], 20, 200, 70, 30, true);
MoveWindow(Button[10],200, 50, 80, 30, true);
MoveWindow(Button[11],200,100, 80, 30, true);
MoveWindow(Button[12],200,150, 80, 30, true);
MoveWindow(Button[13],200,200, 80, 30, true);
MoveWindow(Button[14],110,200, 70, 30, true);
MoveWindow(Edit, 20, 10, 260, 25, true);
return 0;
}
case WM_COMMAND:
{
if (lParam == (LPARAM)Button[0])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '0';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[1])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '1';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[2])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '2';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[3])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '3';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[4])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '4';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[5])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '5';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[6])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '6';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[7])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '7';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[8])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '8';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[9])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '9';
std::strcat(anzeige,zeichen);
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[10])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '+';
iZahl_eins = atoi(anzeige);
std::strcpy(anzeige, " ");
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[11])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '-';
iZahl_eins = atoi(anzeige);
std::strcpy(anzeige, " ");
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[12])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '*';
iZahl_eins = atoi(anzeige);
std::strcpy(anzeige, " ");
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[13])
{
if (HIWORD(wParam) == BN_CLICKED)
zeichen[0] = '/';
iZahl_eins = atoi(anzeige);
std::strcpy(anzeige, " ");
SendMessage(Edit, WM_SETTEXT, 0,(LPARAM) anzeige);
}
if (lParam == (LPARAM)Button[14])
{
if (HIWORD(wParam) == BN_CLICKED)
iZahl_zwei = atoi(anzeige);
if (zeichen[0] == '+')
{
iErgebnis = iZahl_eins + iZahl_zwei;
}
if (zeichen[0] == '-')
{
iErgebnis = iZahl_eins - iZahl_zwei;
}
if (zeichen[0] == '*')
{
iErgebnis = iZahl_eins * iZahl_zwei;
}
if (zeichen[0] == '/')
{
iErgebnis = iZahl_eins / iZahl_zwei;
}
itoa(iErgebnis, anzeige, 20);
SendMessage(Edit, WM_SETTEXT, 0, (LPARAM) anzeige);
}
if (lParam == (LPARAM)Edit)
{
if (HIWORD(wParam) == BN_CLICKED)
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Danke für die Hilfe schon mal im vorraus