MFC的Edit控件里,如何实现输入一组计算表达式:例如5*(3+3)-1,之后点击按钮后输出结果?

在Edit中输入一个运算表达式,例如5*(3+3)-1,之后点击一个按钮空件,将结果显示在这个Edit中,如何实现啊,求帮助,... 在Edit中输入一个运算表达式,例如5*(3+3)-1,之后点击一个按钮空件,将结果显示在这个Edit中,如何实现啊,求帮助, 展开
 我来答
善良的屠夫tu
2011-01-19 · TA获得超过228个赞
知道小有建树答主
回答量:240
采纳率:0%
帮助的人:168万
展开全部
以下是计算公式对话框的实现文件 使用MFC设计框架 使用VC6,.0编译测试通过
不过我的程序功能是简单的实现x+y 你需要改一下输入方式 从文本输入控件取得数据函数GetDlgItemText(IDC_NUM1,num1) 以及最后显示结果SetDlgItemText(IDC_SUM,sum) 是可以一样的
//// sumDlg.cpp : implementation file
//

#include "Stdafx.h"
#include "sum.h"
#include "sumDlg.h"
#include <stdlib.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA

// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL

// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSumDlg dialog

CSumDlg::CSumDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSumDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSumDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CSumDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSumDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSumDlg, CDialog)
//{{AFX_MSG_MAP(CSumDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD, OnAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSumDlg message handlers

BOOL CSumDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CSumDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CSumDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSumDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CSumDlg::OnAdd()
{
// TODO: Add your control notification handler code here
char buffer[20];
UINT num1_size = GetDlgItemText(IDC_NUM1,num1);//获取1
UINT num2_size = GetDlgItemText(IDC_NUM2,num2);
int num1_num = atoi(num1.GetBuffer(num1.GetLength()));
int num2_num = atoi(num2.GetBuffer(num2.GetLength()));
int sum_num = num1_num + num2_num;
sum = itoa(sum_num,buffer,10);
SetDlgItemText(IDC_SUM,sum);//显示2 这两个地放不用修改
num1.ReleaseBuffer();
num2.ReleaseBuffer();
}
敲了半天 希望对你有帮助 也希望能给分
alu59802
2011-01-20 · TA获得超过831个赞
知道小有建树答主
回答量:828
采纳率:0%
帮助的人:678万
展开全部
在消息响应里面写: system("calc");
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式