Create a gist now

Instantly share code, notes, and snippets.

@hoehrmann /Mathe.cpp
Last active Dec 18, 2015

What would you like to do?
MatheMatoFix Version 1.2W, relative of https://gist.github.com/5706362 and name "W" because it's for Windows, while the "D" version was for MS-DOS, at least that's what the COMAL implementation ran under. Also written in November 1998, one of my first C++ and Windows GUI programs. I'll have to see about adding the header and resource files so th…
// MatheMatoFix Version 1.2W
#include <windows.h>
#include "resource.h"
#include <math.h>
//-Globale Variablen---------------------------------
HWND hwnd_Mathe; // Mathematofix Main Window
//HINSTANCE hInst; // Global Instance
//-Globale Variablen ende----------------------------
//-Vordefinierte Proceduren--------------------------
LRESULT CALLBACK WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK Quadratische (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK BiQuadratische(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK GleichungGrad2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK PunktSteigung (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK BiPunkt (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK Info (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
//-Vordefinierte Proceduren ende---------------------
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;
wc.cbSize=sizeof(WNDCLASSEX);
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=WindowProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground=reinterpret_cast<HBRUSH>(COLOR_WINDOW-1);
wc.lpszMenuName=MAKEINTRESOURCE(IDR_MAINMENU);
wc.lpszClassName="MatheMatoFix 1.x";
wc.hIconSm=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
RegisterClassEx(&wc);
hwnd_Mathe=CreateWindow("MatheMatoFix 1.x","MatheMatoFix 1.2W",WS_CAPTION | WS_SYSMENU,0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd_Mathe,nCmdShow);
UpdateWindow(hwnd_Mathe);
while (GetMessage(&msg,NULL,0,0)==TRUE){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
} //**ende WinMain()
double DlgItemValueToDouble(HWND hDlg,int nIDDlgItem)
{
char text[50];
SendDlgItemMessage( hDlg, nIDDlgItem, EM_GETLINE, -1, (LPARAM)text);
return atof(text);
} // end DlgItemValueToDouble()
LRESULT CALLBACK WindowProc(HWND hWnd,UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message){
case WM_PAINT:{
PAINTSTRUCT paintst;
HDC hDC=BeginPaint(hWnd,&paintst);
EndPaint(hWnd,&paintst);
return 0;
} // wm_paint
case WM_DESTROY:
PostQuitMessage(0);
return 0;
// end normal messages
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_QUADRATISCHEGLEICHUNG:
DialogBox(NULL,MAKEINTRESOURCE(IDD_QUADRATISCHEGLEICHUNG),hWnd,(DLGPROC)Quadratische);
return 0;
case ID_BIQUADRATISCHEGLEICHUNG:
DialogBox(NULL,MAKEINTRESOURCE(IDD_BIQUADRATISCHEGLEICHUNG),hWnd,(DLGPROC)BiQuadratische);
return 0;
case ID_GLEICHUNGGRAD2:
DialogBox(NULL,MAKEINTRESOURCE(IDD_GLEICHUNGGRAD2),hWnd,(DLGPROC)GleichungGrad2);
return 0;
case ID_BIPUNKTFORM:
return 0;
case ID_PUNKTSTEIGUNG:
return 0;
case ID_INFO:
DialogBox(NULL,MAKEINTRESOURCE(IDD_INFO),hWnd,(DLGPROC)Info);
return 0;
case ID_DATEI_BEENDEN:
PostQuitMessage(0);
return 0;
default:
return 0;
}
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
}
//*-Dialogeprozeduren------------------------------------------------------------------------------------------
LRESULT CALLBACK Quadratische( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ){
// DialogProzedur für die Quadratische Gleichung
// ----------------------------------------------------------------
char text[20];
double p,q,wurzel;
switch(message){
case WM_INITDIALOG:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
break;
case IDCANCEL:
EndDialog(hDlg,0);
return 0;
case IDC_CALCULATE:
if ( (SendDlgItemMessage( hDlg, IDC_VARP, EM_LINELENGTH, -1, 0)==0) || // Überprüfen ob
(SendDlgItemMessage( hDlg, IDC_VARQ, EM_LINELENGTH, -1, 0)==0) ){ // auch in jedem
MessageBox(hDlg,"\nWäre echt toll, wenn in den Kästchen was stände!!\n","Huch...",MB_OK); // Kästchen was
return 1; // steht. Wenn
} // nicht - Meldung
p=DlgItemValueToDouble(hDlg,IDC_VARP);
q=DlgItemValueToDouble(hDlg,IDC_VARQ);
if ((p/2)*(p/2)-q<0){ // Prüfen
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Keine Lösung" ); // ob rationale
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Keine Lösung" ); // Lösung
return 1; // wenn nicht
} // dann meldung
wurzel=sqrt( (p/2)*(p/2)-q );
_gcvt(p/2+wurzel,10,text);
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
_gcvt(p/2-wurzel,10,text);
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
break;
default:
break;
} // end switch LOWORD
switch(HIWORD(wParam)){
case EN_SETFOCUS:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
break;
default:
break;
} // end switch HIWORD
break; // end case WM_COMMAND
default:
break;
} // end switch message
return 0;
} // end Quadratische
LRESULT CALLBACK BiQuadratische(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
char text[20];
double a,b,c,wurzel;
switch(message){
case WM_INITDIALOG:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
break;
case IDCANCEL:
EndDialog(hDlg,0);
break;
default:
break;
case IDC_CALCULATE:
if ( (SendDlgItemMessage( hDlg, IDC_VARA, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARB, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARC, EM_LINELENGTH, -1, 0)==0)){
MessageBox(hDlg,"\nWäre echt toll, wenn in den Kästchen was stände!!\n","Huch...",MB_OK); // Kästchen was
return 1; // steht. Wenn
} // nicht - Meldung
a=DlgItemValueToDouble(hDlg,IDC_VARA);
b=DlgItemValueToDouble(hDlg,IDC_VARB);
c=DlgItemValueToDouble(hDlg,IDC_VARC);
if ((b*b-4*a*c)<0 || (2*a)==0){ // Prüfen
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Keine Lösung" ); // ob rationale
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Keine Lösung" ); // Lösung
return 1; // wenn nicht
} // dann meldung
wurzel=sqrt( b*b-4*a*c );
_gcvt((-b+wurzel)/(2*a),10,text);
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
_gcvt((-b-wurzel)/(2*a),10,text);
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
break;
}
switch(HIWORD(wParam)){
case EN_SETFOCUS:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
break;
default:
break;
} // end switch HIWORD
break;
default:
break;
} // end switch message
return 0;
}
LRESULT CALLBACK GleichungGrad2( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
char text[20];
double a,b,c,d,e,f,x,y;
switch(message){
case WM_INITDIALOG:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
return 0;
case IDCANCEL:
EndDialog(hDlg,0);
return 0;
default:
break;
case IDC_CALCULATE:
if ( (SendDlgItemMessage( hDlg, IDC_VARA, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARB, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARC, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARD, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARE, EM_LINELENGTH, -1, 0)==0) ||
(SendDlgItemMessage( hDlg, IDC_VARF, EM_LINELENGTH, -1, 0)==0)){
MessageBox(hDlg,"\nWäre echt toll, wenn in den Kästchen was stände!!\n","Huch...",MB_OK); // Kästchen was
return 1; // steht. Wenn
} // nicht - Meldung
a=DlgItemValueToDouble(hDlg,IDC_VARA);
b=DlgItemValueToDouble(hDlg,IDC_VARB);
c=DlgItemValueToDouble(hDlg,IDC_VARC);
d=DlgItemValueToDouble(hDlg,IDC_VARD);
e=DlgItemValueToDouble(hDlg,IDC_VARE);
f=DlgItemValueToDouble(hDlg,IDC_VARF);
if ((a*e-b*d)==0){ // Prüfen
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Divide by zero!!" ); // ob rationale
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Divide by zero!!" ); // Lösung
return 1; // wenn nicht
} // dann meldung
y=(a*f-d*c)/(a*e-b*d);
x=(c-b*y)/a;
_gcvt(x,10,text);
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
_gcvt(y,10,text);
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)text );
break;
}
switch(HIWORD(wParam)){
case EN_SETFOCUS:
SendDlgItemMessage( hDlg, IDC_X1, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
SendDlgItemMessage( hDlg, IDC_X2, WM_SETTEXT, (WPARAM)0, (LPARAM)"Warte auf Parameter" );
break;
default:
break;
} // end switch HIWORD
default:
return 0;
} // end switch message
return 0;
}
LRESULT CALLBACK PunktSteigung( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message){
case WM_INITDIALOG:
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
return 0;
case IDCANCEL:
EndDialog(hDlg,0);
return 0;
default:
break;
}
default:
return 0;
} // end switch message
return 0;
}
LRESULT CALLBACK BiPunkt( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message){
case WM_INITDIALOG:
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
return 0;
case IDCANCEL:
EndDialog(hDlg,0);
return 0;
default:
break;
}
default:
return 0;
} // end switch message
return 0;
}
LRESULT CALLBACK Info( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message){
case WM_INITDIALOG:
//SetWindowPos(hwnd_Mathe, NULL, 1300, 900, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
//ShowWindow(hDlg,SW_HIDE);
SendDlgItemMessage( hDlg, IDC_DIGITAL ,STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)(HANDLE) IDB_BITMAP1 );
SendDlgItemMessage( hDlg, IDC_DESIGN ,STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)(HANDLE) IDB_BITMAP2 );
//ShowWindow(hDlg,SW_SHOW);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
EndDialog(hDlg,0);
return 0;
case IDCANCEL:
EndDialog(hDlg,0);
return 0;
default:
break;
}
default:
return 0;
} // end switch message
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment