| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2080 人关注过本帖
标题:大哥们给个简单计算器的vc程序吧
只看楼主 加入收藏
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
 问题点数:0 回复次数:11 
大哥们给个简单计算器的vc程序吧
大哥们给个简单计算器的vc程序吧,谢谢了
搜索更多相关主题的帖子: vc程序 计算器 
2006-09-15 15:40
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
得分:0 


#include "stdafx.h"
#include "resource.h"
#include <stdio.h>
#define MAX_LOADSTRING 100


HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];


ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK win(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

MSG msg;
HACCEL hAccelTable;


LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MY, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);


if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MY);


while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MY);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hwin;
switch (message)
{
case WM_CREATE:
hwin = CreateDialog(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)win);
ShowWindow(hwin,SW_SHOW);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK win(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int i;
static int a,b,c;
static char txt[9];
static char ct;
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BUTTON1:
if(i==0)
sprintf(txt,"%d",1);
else
{
sprintf(txt,"%d%d",i,1);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON2:
if(i==0)
sprintf(txt,"%d",2);
else
{
sprintf(txt,"%d%d",i,2);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON3:
if(i==0)
sprintf(txt,"%d",3);
else
{
sprintf(txt,"%d%d",i,3);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON4:
if(i==0)
sprintf(txt,"%d",4);
else
{
sprintf(txt,"%d%d",i,4);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON5:
if(i==0)
sprintf(txt,"%d",5);
else
{
sprintf(txt,"%d%d",i,5);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON6:
if(i==0)
sprintf(txt,"%d",6);
else
{
sprintf(txt,"%d%d",i,6);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON7:
if(i==0)
sprintf(txt,"%d",7);
else
{
sprintf(txt,"%d%d",i,7);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON8:
if(i==0)
sprintf(txt,"%d",8);
else
{
sprintf(txt,"%d%d",i,8);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON9:
if(i==0)
sprintf(txt,"%d",9);
else
{
sprintf(txt,"%d%d",i,9);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON10:
if(i==0)
sprintf(txt,"%d",0);
else
{
sprintf(txt,"%d%d",i,0);
}
i=atoi(txt);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
break;
case IDC_BUTTON11:
a=atoi(txt);
ct='+';
SetDlgItemText(hWnd,IDC_EDIT1,"");
i=0;
break;
case IDC_BUTTON12:
a=atoi(txt);
ct='-';
SetDlgItemText(hWnd,IDC_EDIT1,"");
i=0;
break;
case IDC_BUTTON13:
a=atoi(txt);
ct='*';
SetDlgItemText(hWnd,IDC_EDIT1,"");
i=0;
break;
case IDC_BUTTON14:
a=atoi(txt);
ct='/';
SetDlgItemText(hWnd,IDC_EDIT1,"");
i=0;
break;
case IDC_BUTTON15:
b=atoi(txt);
switch(ct)
{
case '+':
c=a+b;
break;
case '-':
c=a-b;
break;
case '*':
c=a*b;
break;
case '/':
c=a/b;
break;
}
sprintf(txt,"%d",c);
SetDlgItemText(hWnd,IDC_EDIT1,txt);
i=0;
break;
case IDM_EXIT:
DestroyWindow(hWnd);
PostQuitMessage(0);
break;
}
}
return 0;
}

不知道怎么上传winzip文件只能贴代码


2006-09-15 16:31
youngky
Rank: 1
等 级:新手上路
威 望:1
帖 子:75
专家分:0
注 册:2006-3-31
收藏
得分:0 

谢谢了


2006-09-15 21:10
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
得分:0 
d:\source\caculation\text1.cpp(2) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
Error executing cl.exe.
我的运行怎么会出现这种错误呢

2006-09-18 15:40
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
得分:0 
不能引入头文件

要在头文件中定义按钮的数据类型#define,没有上传资源文件,上面只是程序的写法(主程序)直接考过去是不好使的.
不知道怎么上传winrar文件

2006-09-18 16:00
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
得分:0 
在附件里上传阿

2006-09-18 16:21
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
得分:0 
radcat,我的邮箱是jxk821015@sohu.com,可以发过来吗?谢谢了

2006-09-18 16:23
radcat
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:306
专家分:45
注 册:2006-9-12
收藏
得分:0 

已发送,请查收


2006-09-18 16:40
jxk821015
Rank: 1
等 级:新手上路
帖 子:41
专家分:0
注 册:2006-8-22
收藏
得分:0 
已收到,谢谢了

2006-09-19 07:33
小单子
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2006-7-11
收藏
得分:0 
我的邮箱是angle820605@163.com能给我也发一份吗?谢谢
2006-09-19 15:32
快速回复:大哥们给个简单计算器的vc程序吧
数据加载中...
 
   



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

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