/*Bleeding's Taschenrechner*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.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 hAdd;
static HWND hSub;
static HWND hMul;
static HWND hDiv;
static HWND hWur;
static HWND hQua;
static HWND hSin;
static HWND hCos;
static HWND hTan;
static HWND hCot;
static HWND hlog;
static HWND hlog2;
static HWND hlog10;
static HWND hNum1;
static HWND hNum2;
static HWND hRes;
char szBuffer[20];
double fNum1;
double fNum2;
switch (message)
{
case WM_CREATE:
hAdd = CreateWindow ( "button", "Addieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
100, 200, 100, 40, hwnd, (HMENU)1,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hSub = CreateWindow ( "button", "Subtrahieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
400, 200, 100, 40, hwnd, (HMENU)2,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hMul = CreateWindow ( "button", "Multiplizieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
100, 250, 100, 40, hwnd, (HMENU)3,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hDiv = CreateWindow ( "button", "Dividieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
400, 250, 100, 40, hwnd, (HMENU)4,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hWur = CreateWindow ( "button", "Wurzel", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
400, 300, 100, 40, hwnd, (HMENU)5,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hQua = CreateWindow ( "button", "Quadrieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
100, 300, 100, 40, hwnd, (HMENU)6,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hSin = CreateWindow ( "button", "Sinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
110, 400, 75, 20, hwnd, (HMENU)7,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hCos = CreateWindow ( "button", "Cosinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
210, 400, 75, 20, hwnd, (HMENU)8,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hTan = CreateWindow ( "button", "Tangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
310, 400, 75, 20, hwnd, (HMENU)9,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hCot = CreateWindow ( "button", "Cotangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
410, 400, 75, 20, hwnd, (HMENU)10,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hlog = CreateWindow ( "button", "log", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
165, 450, 75, 20, hwnd, (HMENU)14,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hlog2 = CreateWindow ( "button", "log2", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
255, 450, 75, 20, hwnd, (HMENU)15,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hlog10 = CreateWindow ( "button", "log10", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
345, 450, 75, 20, hwnd, (HMENU)16,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hNum1 = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
150, 100, 100, 30, hwnd, (HMENU)11,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hNum2 = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
350, 100, 100, 30, hwnd, (HMENU)12,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
hRes = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
230, 500, 150, 40, hwnd, (HMENU)13,
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
return 0;
case WM_COMMAND:
if ( LOWORD (wParam) ==1)
{
GetDlgItemText( hwnd, 11, szBuffer, sizeof(szBuffer)/sizeof(char) ); // hNum1
fNum1 = atof(szBuffer);
GetDlgItemText ( hwnd,12, szBuffer, sizeof(szBuffer)/sizeof(char) ); // hNum2
fNum2 = atof(szBuffer);
_gcvt( (fNum1 + fNum2), 10, szBuffer );
SetDlgItemText(hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==2)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( (fNum1-fNum2), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==3)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( (fNum1*fNum2), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==4)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( (fNum1/fNum2), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==5)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( sqrt(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==6)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( (fNum1*fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==7)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( sin(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==8)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( cos(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==9)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( tan(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==10)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( tanh(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==14)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( log(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==15)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( (fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer);
}
if ( LOWORD (wParam) ==16)
{
GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum1=atof(szBuffer);
GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
fNum2 =atof(szBuffer);
_gcvt ( log10(fNum1), 10, szBuffer );
SetDlgItemText (hwnd, 13, szBuffer );
}
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}