| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 652 人关注过本帖
标题:[原创]VC对话框--计算器
只看楼主 加入收藏
tyc1920
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-10-27
收藏
 问题点数:0 回复次数:7 
[原创]VC对话框--计算器

*/ --------------------------------------------------------------------------------------
*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: tyc1920 E-mail:tyc.1920@yahoo.com.cn QQ:609670447
*/ 时间: 2007-11-12 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------

//Win32 Application

#include <windows.h>
#include "resource.h"

HINSTANCE hInst;
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);


BOOL CALLBACK DlgProc(HWND hdlg,UINT uMsg,WPARAM wParam,LPARAM lParam);

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
HWND hwnd;
WNDCLASS wc;
MSG msg;

wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WindowProc;
wc.lpszClassName="MyWndClass";
wc.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wc.style=0;

if(!RegisterClass(&wc))
{
MessageBeep(0);
return FALSE;
}

hwnd=CreateWindow(
"MyWndClass",
"My Dialog!",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
hInst=hInstance;

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_COMPUTER:
DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
break;
case IDM_EXIT:
PostQuitMessage(0);
break;
case IDM_ABOUT:
MessageBox(hwnd,"作者:安师大吴鹏","关于",0);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

BOOL CALLBACK DlgProc(HWND hdlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static double fNum1=0,fNum2=0,fNum3=0;
static char str1[10],str2[20],str3[30];
static int Op=0;
static BOOL flt=0;
switch(uMsg)
{
case WM_INITDIALOG:
return 1;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1: //清除按钮...
strcpy(str1,"");
strcpy(str2,"");
strcpy(str3,"");
flt=0;
Op=0;
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"");
break;
case IDC_BUTTON18: //0...
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"0");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"0");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON19:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"1");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"1");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON20:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"2");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"2");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON21:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"3");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"3");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON22:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"4");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"4");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON23:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"5");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"5");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON24:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"6");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"6");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON25:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"7");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"7");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON26:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"8");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"8");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON27:
if(Op==0)
{
if(str1[0]=='0'&&str1[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str1,"9");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
}
else
{
if(str2[0]=='0'&&str2[1]!='.')
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
else
{
strcat(str2,"9");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
}


break;
case IDC_BUTTON28: //等于按钮...
if(Op!=0)
{
fNum1=atof(str1);
fNum2=atof(str2);

switch(Op)
{
case 1:
fNum3=fNum1+fNum2;
break;
case 2:
fNum3=fNum1-fNum2;
break;
case 3:
fNum3=fNum1*fNum2;
break;
case 4:
fNum3=fNum1/fNum2;
break;
}
itoa(fNum3,str3,10);
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str3);
Op=0;
strcpy(str1,"");
strcpy(str2,"");
}
break;
case IDC_BUTTON29: //小数点按钮...
if(Op==0)
{
if(flt==0&&str1[0]!='\0')
{
flt=1;
strcat(str1,".");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str1);
}
else SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
}
else
{
if(flt==0&&str2[0]!='\0')
{
flt=1;
strcat(str2,".");
SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),str2);
}
else SetWindowText(GetDlgItem(hdlg,IDC_EDIT1),"输入有误!");
}

break;
case IDC_BUTTON30: //加法...
Op=1;
flt=0;
break;
case IDC_BUTTON31: //减法...
Op=2;
flt=0;
break;
case IDC_BUTTON32: //乘法...
Op=3;
flt=0;
break;
case IDC_BUTTON33: //除法...
Op=4;
flt=0;
break;
}
break;
case WM_CLOSE:
EndDialog(hdlg,0);
return 1;
}
return 0;

}

搜索更多相关主题的帖子: 计算器 对话框 
2007-11-12 09:18
上来找找
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-5-7
收藏
得分:0 
支持
2007-11-12 09:19
h105105
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-10-30
收藏
得分:0 
好长  支持一下
2007-11-14 16:32
h105105
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-10-30
收藏
得分:0 
fatal error C1083: Cannot open include file: 'resource.h': No such file or directory
bulid 时出现 怎么回事?
2007-11-14 16:37
tyc1920
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-10-27
收藏
得分:0 

我先前插入的资源没有传上去,你可以点击下载下面的源程序代码:


[此贴子已经被作者于2007-11-15 21:43:57编辑过]

附件: 游客没有浏览附件的权限,请 登录注册
2007-11-15 21:42
tyc1920
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-10-27
收藏
得分:0 
回复:(h105105)fatal error C1083: Cannot open in...

我先前插入的资源没有传上去,你可以点击下载下面的源程序代码:



附件: 游客没有浏览附件的权限,请 登录注册
2007-11-15 21:43
yybruce
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-11-10
收藏
得分:0 
支持
2007-11-15 22:32
yingtian4
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-11-15
收藏
得分:0 
有点长
2007-11-15 23:06
快速回复:[原创]VC对话框--计算器
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018624 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved