⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlg.cpp

📁 根据《VC++6.0 用户界面制作技术与应用实例》写的一些代码
💻 CPP
字号:
// Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "test2.h"
#include "Dlg.h"
#include "math.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlg dialog


CDlg::CDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlg)
	m_x1 = 0.0;
	m_x2 = 0.0;
	m_result = 0.0;
	//}}AFX_DATA_INIT
}


void CDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlg)
	DDX_Text(pDX, IDC_EDIT_X1, m_x1);
	DDX_Text(pDX, IDC_EDIT_X2, m_x2);
	DDX_Text(pDX, IDC_EDIT_RESULT, m_result);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlg, CDialog)
	//{{AFX_MSG_MAP(CDlg)
	ON_BN_CLICKED(IDC_COMPUTE, OnCompute)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlg message handlers



void CDlg::OnCompute() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO1);
	int cursel = pComboBox->GetCurSel();
	char tubf[80];
	int ret = pComboBox->GetLBText(cursel , tubf);

	ASSERT(ret != CB_ERR);

	switch(tubf[0])
	{
	case '+':
		m_result = m_x1+m_x2;
		break;
	case '-':
		m_result = m_x1-m_x2;
		break;
	case '*':
		m_result = m_x1*m_x2;
		break;
	case '/':
		if(fabs(m_x2)>1e-16)
			m_result = m_x1/m_x2;
		else
			AfxMessageBox("Can't compute!!!!!!");
		break;
	default:
		break;
	}

	sprintf(tubf , "%f",m_result);
	SetDlgItemText(IDC_EDIT_RESULT,tubf);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -