6/24/10

Calculator

Buzz It
#include
#include"resource.h"
long _stdcall myfun(HWND,UINT,UINT,long);
BOOL CALLBACK DProc(HWND,UINT,UINT,long);
WNDCLASS a;
HWND hd;
int _stdcall WinMain(HINSTANCE i,HINSTANCE j,char*k,int l)
{
HWND h;
MSG m;
a.hInstance=i;
a.lpszClassName="hello";
a.lpfnWndProc=myfun;
a.hCursor=LoadCursor(0,IDC_ARROW);
a.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
RegisterClass(&a);
h=CreateWindow("hello","pressok",WS_OVERLAPPEDWINDOW,100,100,200,250,0,0,i,0);
ShowWindow(h,l);
UpdateWindow(h);
hd=CreateDialog(i,MAKEINTRESOURCE(IDD_DIALOG1),h,DProc);
while(GetMessage(&m,0,0,0))

{
if((hd==0)(!(IsDialogMessage (hd,&m))))
{
TranslateMessage(&m);
DispatchMessage(&m);
}
}
return 0;
}
long _stdcall myfun(HWND w,UINT x,UINT y,long z)
{
switch(x)
{
case WM_LBUTTONDOWN:
ShowWindow(hd,1);
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(w,x,y,z);
}
return 0;
}
BOOL CALLBACK DProc(HWND w,UINT x,UINT y,long z)
{
static int f,s,r;
TCHAR str[10];
HDC d;
switch(x)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
GetDlgItemText (hd,IDC_EDIT1,str,10);
f=atoi (str);
GetDlgItemText (hd,IDC_EDIT2,str,10);
s=atoi(str);
switch(LOWORD(y))
{
case IDC_PLUSBUTTON:
d=GetDC(w);
r=f+s;
wsprintf(str,"%i",r);
SetDlgItemText (hd,IDC_EDIT3,str);
return 0;
case IDC_MINUSBUTTON:
d=GetDC(w);
r=f-s;
wsprintf(str,"%i",r);
SetDlgItemText (hd,IDC_EDIT3,str);
return 0;
case IDC_MULTBUTTON:
d=GetDC(w);
r=f*s;
wsprintf(str,"%i",r);
SetDlgItemText (hd,IDC_EDIT3,str);
return 0;
case IDC_DIVBUTTON:
d=GetDC(w);
r=f/s;
wsprintf(str,"%i",r);
SetDlgItemText (hd,IDC_EDIT3,str);
return 0;
case IDOK:
EndDialog(w,1);
return true;
case IDCANCEL:
EndDialog(w,1);
return true;

}
return true;
break;
}
return false;
}



Output

0 comments:

Post a Comment