#include <windows.h>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "WindowsApp";
HWND hwnd;
HWND number_1;
HWND number_2;
HWND result;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Калькулятор",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
700,
700,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
HWND lab_1= CreateWindow(TEXT("static"),
TEXT("Число 1"),
WS_VISIBLE | WS_CHILD ,
0, 0, 150,25,
hwnd, 0, hThisInstance, NULL);
HWND lab_2= CreateWindow(TEXT("static"),
TEXT("Число 2"),
WS_VISIBLE | WS_CHILD ,
0, 70, 150,25,
hwnd, 0, hThisInstance, NULL);
HWND lab_3= CreateWindow(TEXT("static"),
TEXT("Результат"),
WS_VISIBLE | WS_CHILD ,
0, 140, 150,25,
hwnd, 0, hThisInstance, NULL);
number_1= CreateWindow(TEXT("edit"),
TEXT(""),
WS_VISIBLE | WS_CHILD ,
0, 30, 150,25,
hwnd, 0, hThisInstance, NULL);
number_2 = CreateWindow(TEXT("edit"),
TEXT(""),
WS_VISIBLE | WS_CHILD ,
0,100, 150,25,
hwnd, 0, hThisInstance, NULL);
result = CreateWindow(TEXT("edit"),
TEXT(""),
WS_VISIBLE | WS_CHILD ,
0,170, 150,25,
hwnd, 0, hThisInstance, NULL);
HWND operation_1 = CreateWindow(TEXT("button"),
TEXT("Сложение"),
WS_VISIBLE | WS_CHILD ,
0, 200, 100, 35,
hwnd, (HMENU)1000, hThisInstance, NULL);
HWND operation_2 = CreateWindow(TEXT("button"),
TEXT("Вычитание"),
WS_VISIBLE | WS_CHILD ,
100, 200, 100, 35,
hwnd, (HMENU)1001, hThisInstance, NULL);
HWND operation_3 = CreateWindow(TEXT("button"),
TEXT("Умножение"),
WS_VISIBLE | WS_CHILD ,
200, 200, 100, 35,
hwnd, (HMENU)1002, hThisInstance, NULL);
HWND operation_4 = CreateWindow(TEXT("button"),
TEXT("Деление"),
WS_VISIBLE | WS_CHILD ,
300, 200, 100, 35,
hwnd, (HMENU)1003, hThisInstance, NULL);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
int operation_1 = 1000;
int operation_2 = 1001;
int operation_3 = 1002;
int operation_4 = 1003;
if (wParam == operation_1)
{
char num_1[10];
char num_2[10];
char num_3[10];
GetWindowText(number_1,num_1,10);
GetWindowText(number_2,num_2,10);
int r = atoi(num_1)+atoi(num_2);
sprintf (num_3, "%d",r);
SetWindowText(result,num_3);
}
if (wParam == operation_2)
{
char num_1[10];
char num_2[10];
char num_3[10];
GetWindowText(number_1,num_1,10);
GetWindowText(number_2,num_2,10);
int r = atoi(num_1)-atoi(num_2);
sprintf (num_3, "%d",r);
SetWindowText(result,num_3);
}
if (wParam == operation_3)
{
char num_1[10];
char num_2[10];
char num_3[10];
GetWindowText(number_1,num_1,10);
GetWindowText(number_2,num_2,10);
int r = atoi(num_1)*atoi(num_2);
sprintf (num_3, "%d",r);
SetWindowText(result,num_3);
}
if (wParam == operation_4)
{
char num_1[10];
char num_2[10];
char num_3[10];
GetWindowText(number_1,num_1,10);
GetWindowText(number_2,num_2,10);
int r = atoi(num_1)/atoi(num_2);
sprintf (num_3, "%d",r);
SetWindowText(result,num_3);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|