资源描述:
《windows计算器程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、一windowsapi风格的计算器程序:1直接在主窗体上创建向导生成默认的窗口程序,将unicode支持改成不限,其它地方不动。消息响应函数的内容为:LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam){intwmId,wmEvent;PAINTSTRUCTps;HDChdc;staticHWNDhEdit1,hEdit2,hResult,hButton1,hStatic1,hStatic2;switch(message){
2、caseWM_CREATE:hEdit1=::CreateWindowA("EDIT",NULL,WS_CHILD
3、WS_VISIBLE
4、WS_BORDER,30,30,100,20,hWnd,(HMENU)IDC_EDIT1,hInst,NULL);hEdit2=::CreateWindowA("EDIT",NULL,WS_CHILD
5、WS_VISIBLE
6、WS_BORDER,230,30,100,20,hWnd,(HMENU)IDC_EDIT2,hInst,NULL);hResult=::CreateWin
7、dowA("EDIT",NULL,WS_CHILD
8、WS_VISIBLE
9、WS_BORDER,430,30,100,20,hWnd,(HMENU)IDC_EDIT3,hInst,NULL);hButton1=::CreateWindowA("BUTTON",NULL,WS_CHILD
10、WS_VISIBLE
11、WS_BORDER,130,130,100,20,hWnd,(HMENU)IDC_BUTTON1,hInst,NULL);::SetWindowText(hButton1,"执行加法");hStatic1=:
12、:CreateWindowA("STATIC",NULL,WS_CHILD
13、WS_VISIBLE,150,30,20,20,hWnd,NULL,hInst,NULL);hStatic2=::CreateWindowA("STATIC",NULL,WS_CHILD
14、WS_VISIBLE,350,30,20,20,hWnd,NULL,hInst,NULL);::SetWindowText(hStatic1,"+");::SetWindowText(hStatic2,"=");break;caseWM_COMMAND
15、:wmId=LOWORD(wParam);wmEvent=HIWORD(wParam);//Parsethemenuselections:switch(wmId){caseIDC_BUTTON1:charop1[11],op2[11],result[11];intn1,n2,nResult;::GetWindowText(hEdit1,op1,10);::GetWindowText(hEdit2,op2,10);n1=atoi(op1);n2=atoi(op2);nResult=n1+n2;::sprintf(
16、result,"%d",nResult);::SetWindowText(hResult,result);break;caseIDM_ABOUT:DialogBox(hInst,MAKEINTRESOURCE(IDD_ABOUTBOX),hWnd,About);break;caseIDM_EXIT:DestroyWindow(hWnd);break;default:returnDefWindowProc(hWnd,message,wParam,lParam);}break;caseWM_PAINT:hdc=Be
17、ginPaint(hWnd,&ps);//TODO:Addanydrawingcodehere...EndPaint(hWnd,&ps);break;caseWM_DESTROY:PostQuitMessage(0);break;default:returnDefWindowProc(hWnd,message,wParam,lParam);}return0;}变化的参见阴影部分,主要包括控件句柄变量的声明,响应WM_CREATE创建控件,以及在WM_COMMAND响应中添加BUTTON的响应函数三部分内容。创建
18、空间的时候声明了控件的ID值,以后可以根据ID获得控件句柄。对于静态文本控件,基本不会有什么操作,所以没给它分配ID。这些ID添加到resouce.h声明文件中#defineIDI_CALWINAPI107#defineIDI_SMALL108#defineIDC_CALWINAPI109#defineIDC_MYICON2#ifndefIDC_STATIC#defineIDC_STA