1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#define ID_TEXTBOXA 1
#define ID_TEXTBOXB 2
#define ID_TEXTBOXC 3
#define ID_TEXTBOXD 4
#define ID_TEXTBOXE 6
#define ID_BUTTON 5
#define BUFFER 14
TCHAR tchBuffer[BUFFER];
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:{
{
CreateWindow(TEXT("EDIT"), TEXT("A"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
20, 10, 200, 20, hwnd, (HMENU) ID_TEXTBOXA, NULL, NULL);
}
{
CreateWindow(TEXT("EDIT"), TEXT("B"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
20, 40, 200, 20, hwnd, (HMENU) ID_TEXTBOXB, NULL, NULL);
}
{
CreateWindow(TEXT("EDIT"), TEXT("C"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
20, 70, 200, 20, hwnd, (HMENU) ID_TEXTBOXC, NULL, NULL);
}
{
CreateWindow(TEXT("STATIC"), TEXT("X"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
10, 300, 200, 20, hwnd, (HMENU) ID_TEXTBOXD, NULL, NULL);
}
{
CreateWindow(TEXT("STATIC"), TEXT("X"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
10, 250, 200, 20, hwnd, (HMENU) ID_TEXTBOXE, NULL, NULL);
}
{
CreateWindow(TEXT("BUTTON"), TEXT("Solve"), WS_VISIBLE | WS_CHILD,
250, 300, 130, 20, hwnd, (HMENU) ID_BUTTON, NULL, NULL);
}
break;
}
case WM_COMMAND:{
if(LOWORD(wParam) == ID_BUTTON){
double a;
double b;
double c;
double d;
double f;
double g;
a = GetDlgItemInt(hwnd, ID_TEXTBOXA, NULL, TRUE);
if( a == 0)
{
MessageBox(hwnd, "Cannot divide by zero", "Error", MB_OK | MB_ICONERROR);
break;
}
b = GetDlgItemInt(hwnd, ID_TEXTBOXB, NULL, TRUE);
c = GetDlgItemInt(hwnd, ID_TEXTBOXC, NULL, TRUE);
d = sqrt(((b*b)-(4*a*c)));
f = ((-b+d)/(2*a));
g = ((-b-d)/(2*a));
if (((b*b)-(4*a*c)) < 0 )
{
MessageBox(hwnd, "Cannot square root a negative number", "Error", MB_OK | MB_ICONERROR);
break;
}
SetDlgItemText(hwnd, ID_TEXTBOXD, _gcvt((f), 13, tchBuffer));
SetDlgItemText(hwnd, ID_TEXTBOXE, _gcvt((g), 13, tchBuffer));
}
break;
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|