| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3990 人关注过本帖
标题:关于MFC编计算器小数点要怎么实现
只看楼主 加入收藏
as466043710
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-1-6
收藏
 问题点数:0 回复次数:3 
关于MFC编计算器小数点要怎么实现
// ComputerDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Computer.h"
#include "ComputerDlg.h"
#include<math.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char sign=0;
double value;
int i=0;

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CComputerDlg dialog

CComputerDlg::CComputerDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CComputerDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CComputerDlg)
    m_num = 0.0;
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CComputerDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CComputerDlg)
    DDX_Text(pDX, IDC_EDIT1, m_num);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CComputerDlg, CDialog)
    //{{AFX_MSG_MAP(CComputerDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_BUTTON0, OnButton0)
    ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
    ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
    ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
    ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
    ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
    ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
    ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
    ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
    ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
    ON_BN_CLICKED(IDC_BUTTONClean, OnBUTTONClean)
    ON_BN_CLICKED(IDC_BUTTONadd, OnBUTTONadd)
    ON_BN_CLICKED(IDC_BUTTONequ, OnBUTTONequ)
    ON_BN_CLICKED(IDC_BUTTONreduce, OnBUTTONreduce)
    ON_BN_CLICKED(IDC_BUTTONdiv, OnBUTTONdiv)
    ON_BN_CLICKED(IDC_BUTTONmul, OnBUTTONmul)
    ON_BN_CLICKED(IDC_BUTTONDel, OnBUTTONDel)
    ON_BN_CLICKED(IDC_BUTTONsqrt, OnBUTTONsqrt)
    ON_BN_CLICKED(IDC_BUTTONDel2, OnBUTTONDel2)
    ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
    ON_BN_CLICKED(IDC_dian, Ondian)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComputerDlg message handlers

BOOL CComputerDlg::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 CComputerDlg::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 CComputerDlg::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 CComputerDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CComputerDlg::OnButton0()
{
   
    UpdateData(TRUE);
    if (i++==0)      //清零
       m_num=0;   
   
    if (i>10)        //限制最大只能输入10位数
       UpdateData(false);
    else
       m_num=m_num*10;

    UpdateData(false);
}

void CComputerDlg::OnButton1()
{
   
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+1;

    UpdateData(false);
}

void CComputerDlg::OnButton2()
{
   
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+2;

    UpdateData(false);   
}

void CComputerDlg::OnButton3()
{
        
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+3;

    UpdateData(false);   
}

void CComputerDlg::OnButton4()
{
   
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+4;

    UpdateData(false);
}

void CComputerDlg::OnButton5()
{
   
    UpdateData(true);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+5;

    UpdateData(false);
}

void CComputerDlg::OnButton6()
{
   
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
     
     if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+6;

    UpdateData(false);
}

void CComputerDlg::OnButton7()
{
   
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;
   
    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+7;

    UpdateData(false);
}

void CComputerDlg::OnButton8()
{
        
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;

    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+8;

    UpdateData(false);
}

void CComputerDlg::OnButton9()
{
        
    UpdateData(TRUE);
    if (i++==0)
       m_num=0;

    if (i>10)        
       UpdateData(false);
    else
       m_num=m_num*10+9;

    UpdateData(false);
}


void CComputerDlg::OnBUTTONadd()
{
   
    UpdateData(TRUE);
    value=m_num;
    sign='+';
    i=0;
   
    UpdateData(false);

}

void CComputerDlg::OnBUTTONreduce()
{
    UpdateData(TRUE);
    value=m_num;
    sign='-';
    i=0;
   
    UpdateData(false);
}

void CComputerDlg::OnBUTTONdiv()
{
    UpdateData(TRUE);
    value=m_num;
    sign='/';
    i=0;
   
    UpdateData(false);
}

void CComputerDlg::OnBUTTONmul()
{
    UpdateData(TRUE);
    value=m_num;
    sign='*';
    i=0;
   
    UpdateData(false);
}
void CComputerDlg::OnBUTTONequ()
{
    UpdateData(TRUE);
    if (sign=='+')
    m_num=value+m_num;
    if (sign=='-')
    m_num=value-m_num;
    if (sign=='/')
    m_num=value/m_num;
    if (sign=='*')
    m_num=value*m_num;
    if (sign=='^')
    m_num=value*m_num;
    sign=0;
    i=0;
    UpdateData(false);
   
   
   
}

void CComputerDlg::OnBUTTONsqrt()
{
    UpdateData(true);
    m_num=sqrt(m_num);
    i=0;
    UpdateData(false);
   
}


void CComputerDlg::OnBUTTONClean()
{
    UpdateData(TRUE);
    m_num=0;
    i=0;
    sign=0;
    UpdateData(false);   
}


void CComputerDlg::OnBUTTONDel()
{
   
    UpdateData(true);
    if (i--==0)
    {
        m_num=0;
    }
    m_num=(m_num-(int)m_num%10)/10;
    UpdateData(false);
}


void CComputerDlg::OnBUTTONDel2()
{
    UpdateData(TRUE);
    value=m_num;
    sign='^';
    i=0;
   
    UpdateData(false);
    // TODO: Add your control notification handler code here
   
}

void CComputerDlg::OnButton10()
{    UpdateData(true);
    m_num=-1*m_num;
    i=0;
    UpdateData(false);
    // TODO: Add your control notification handler code here
   
}

void CComputerDlg::Ondian()
{
    // TODO: Add your control notification handler code here
}


搜索更多相关主题的帖子: 计算器 MFC 
2010-01-13 15:52
as466043710
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-1-6
收藏
得分:0 
求高手指教下
2010-01-13 15:58
as466043710
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-1-6
收藏
得分:0 
555555...................
2010-01-14 13:58
wangchunbao
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2010-11-6
收藏
得分:0 
我也是刚刚开始学  前几天做了一个计算器  是用字符串实现小数点
2010-11-14 16:16
快速回复:关于MFC编计算器小数点要怎么实现
数据加载中...
 
   



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

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