win32sdk计算器

//win32gui版计算器
//Main.cpp
// jsq.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include "MainDlg.h"
#include <COMMCTRL.H>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
//Enable IPAddress Calendar.etc
InitCommonControls();
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, Main_Proc);
return 0;
}


//MainDlg.cpp
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
#include "stdio.h"
//#include "string.h"
#include "stdlib.h"

int top=0,topop=1,msgtop=0;
char optr[256]="#";//初始化操作符栈;
char msg[256]="#";//初始表达式栈;
double result[256]={-1};//操作数栈,计算结束后的结果放在了第0个下标中;
double jieguo=0;




void pushmsg(char ch)
{
msg[msgtop++]=ch;//将按键字符数据送入表达式栈msg;
}

void backspace(HWND hwnd)
{
if(0==msgtop)
{
EnableWindow(GetDlgItem(hwnd,IDC_BUTTON20),FALSE);
}
else
{
msg[(--msgtop)--]='\0';//按下backspace后删除前一个字符;
++msgtop;
}

}

double gettopnd()//取得操作数栈顶符号
{
return result[top-1];
}
char gettopop()//取得操作符栈顶符号
{
return optr[topop-1];
}

void pushnd(double ch)//操作数入栈
{
result[top++]=ch;
}

void pushop(char ch)//操作符入栈
{
optr[topop++]=ch;
}

double popnd()//弹出操作数
{
return result[--top];
}
char popop()//弹出操作符
{
return optr[--topop];
}


char IsOprator(char m )//判断字符是否是操作符,是则返回操作符assci,否为0;
{
switch(m)
{
case '+':
case '-':
case '*':
case '/':
case '(':
case ')':
case '#':return m;break;
default: return 0;
}
}

int FmtStr(char msg[],int N)//格式化表达式,主要是将负数(-x)转化为(0-x)的形式以统一使用后续算法,同理可增加新的计算功能;
{
int tmp=0;//临时变量,主要是保存表达式增加的位数(表达式增加的长度)
for (int i=0;i<N-1;i++)//总共循环表达式的长度那么多次;
{
if(msg[i]=='-'&&msg[i-1]=='(')//取当前字符并判断该字符是否是负号且它的上一个字符是左括号,确定这个符号为负而不是减;
{
for(int t=N+1;t!=i;t--)//若为负号,则向后取数直到遇到右括号时终止;
{
msg[t]=msg[t-1];//将负号后,右括号前的所有字符作为一个操作数;
}
m
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值