DreamForse
Новенький
Offline
|
|
« : 18-02-2014 17:52 » |
|
Добрый вечер,разрабатываю калькулятор на winapi хотелось бы узнать как реализовать функции что бы найти синус,косинус,корень квадратный,степень от числа,буду благодарен если кто-то подскажет функции или поможет дописать,пишу в C++ Builder #include <windows.h> #include <windowsx.h> #include <stdio.h> #include <stdlib.h> #include <math.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); HWND fieldedit1,fieldedit2,fieldedit3; HWND button1,button2,button3,button4,button5,button6,button7; char szClassName[] = "Mywindow";
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{ HWND hwnd; 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,0,0,350,400,NULL,NULL,NULL,NULL); fieldedit1=CreateWindow("EDIT","",WS_VISIBLE|WS_CHILD,30,50,125,30,hwnd,NULL,NULL,NULL); fieldedit2=CreateWindow("EDIT","",WS_VISIBLE|WS_CHILD,30,90,125,30,hwnd,NULL,NULL,NULL); fieldedit3=CreateWindow("EDIT","Ðåçóëüòàò",WS_VISIBLE|WS_CHILD|ES_CENTER|ES_READONLY ,200,75,100,25,hwnd,NULL,NULL,NULL);
button1=CreateWindow("button","+",WS_VISIBLE|WS_CHILD,50,150,40,40,hwnd,NULL,NULL,NULL); button2=CreateWindow("button","-",WS_VISIBLE|WS_CHILD,100,150,40,40,hwnd,NULL,NULL,NULL); button3=CreateWindow("button","/",WS_VISIBLE|WS_CHILD,150,150,40,40,hwnd,NULL,NULL,NULL); button4=CreateWindow("button","*",WS_VISIBLE|WS_CHILD,200,150,40,40,hwnd,NULL,NULL,NULL); button5=CreateWindow("button","Î÷èñòèòè",WS_VISIBLE|WS_CHILD,50,200,90,40,hwnd,NULL,NULL,NULL); button6=CreateWindow("button","Âèõ³ä",WS_VISIBLE|WS_CHILD,150,200,90,40,hwnd,NULL,NULL,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:
if ((HWND)lParam == button2) { int d1 = 0,d2 = 0; char number1[10]; Edit_GetLine(fieldedit1,0,number1,10); d1 = atoi(number1); char number2[10]; Edit_GetLine(fieldedit2,0,number2,10); d2 = atoi(number2); char result[10]; if (d1-d2) { itoa (d1-d2,result,10); Edit_SetText(fieldedit3,result); } else { Edit_SetText(fieldedit3,"0"); } } if ((HWND)lParam == button1) { int d1 = 0,d2 = 0; char number1[10]; Edit_GetLine(fieldedit1,0,number1,10); d1 = atoi(number1); char number2[10]; Edit_GetLine(fieldedit2,0,number2,10); d2 = atoi(number2); char result[10];
if (d1+d2) { itoa (d1+d2,result,10); Edit_SetText(fieldedit3,result); } else { Edit_SetText(fieldedit3,"ERROR"); } } if ((HWND)lParam == button3) { int d1 = 0,d2 = 0; char number1[10]; Edit_GetLine(fieldedit1,0,number1,10); d1 = atoi(number1); char number2[10]; Edit_GetLine(fieldedit2,0,number2,10); d2 = atoi(number2); char result[10];
if (d2 != 0) { itoa (d1/d2,result,10); Edit_SetText(fieldedit3,result); } else { Edit_SetText(fieldedit3,"ERROR"); }
} if ((HWND)lParam == button4) { int d1 = 0,d2 = 0; char number1[10]; Edit_GetLine(fieldedit1,0,number1,10); d1 = atoi(number1); char number2[10]; Edit_GetLine(fieldedit2,0,number2,10); d2 = atoi(number2); char result[10];
if (d1*d2) { itoa (d1*d2,result,10); Edit_SetText(fieldedit3,result); } else { Edit_SetText(fieldedit3,"ERROR"); } } if ((HWND)lParam == button5) { int d1 = 0,d2 = 0; char number1[10]; Edit_GetLine(fieldedit1,0,number1,10); d1 = atoi(number1); char number2[10]; Edit_GetLine(fieldedit2,0,number2,10); d2 = atoi(number2); char result[10]; { Edit_SetText(fieldedit3,""); } } if ((HWND)lParam == button6) { SendMessage(hwnd,WM_CLOSE,0,0); } break; case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }
return 0; }
|