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

📄 ex_calculator04dlg.cpp

📁 C++控件的使用,计算器的设计 有典型起步提高进阶和提高
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// EX_Calculator04Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "EX_Calculator04.h"
#include "EX_Calculator04Dlg.h"

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

char char_radio='D';
int value=0;
CString str;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CEX_Calculator04Dlg dialog

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

void CEX_Calculator04Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEX_Calculator04Dlg)
	DDX_Control(pDX, IDC_F_BUTTON, m_FButton);
	DDX_Control(pDX, IDC_E_BUTTON, m_EButton);
	DDX_Control(pDX, IDC_D_BUTTON, m_DButton);
	DDX_Control(pDX, IDC_C_BUTTON, m_CButton);
	DDX_Control(pDX, IDC_B_BUTTON, m_BButton);
	DDX_Control(pDX, IDC_A_BUTTON, m_AButton);
	DDX_Control(pDX, IDC_9_BUTTON, m_9Button);
	DDX_Control(pDX, IDC_8_BUTTON, m_8Button);
	DDX_Control(pDX, IDC_OUTPUT_CHECK, m_OutputCheck);
	DDX_Control(pDX, IDC_INPUT_CHECK, m_InputCheck);
	DDX_Text(pDX, IDC_EDIT2, m_InputEdit);
	DDX_Text(pDX, IDC_EDIT3, m_OutputEdit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEX_Calculator04Dlg, CDialog)
	//{{AFX_MSG_MAP(CEX_Calculator04Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_0_BUTTON, On0Button)
	ON_BN_CLICKED(IDC_1_BUTTON, On1Button)
	ON_BN_CLICKED(IDC_2_BUTTON, On2Button)
	ON_BN_CLICKED(IDC_3_BUTTON, On3Button)
	ON_BN_CLICKED(IDC_4_BUTTON, On4Button)
	ON_BN_CLICKED(IDC_5_BUTTON, On5Button)
	ON_BN_CLICKED(IDC_6_BUTTON, On6Button)
	ON_BN_CLICKED(IDC_7_BUTTON, On7Button)
	ON_BN_CLICKED(IDC_8_BUTTON, On8Button)
	ON_BN_CLICKED(IDC_9_BUTTON, On9Button)
	ON_BN_CLICKED(IDC_A_BUTTON, OnAButton)
	ON_BN_CLICKED(IDC_B_BUTTON, OnBButton)
	ON_BN_CLICKED(IDC_C_BUTTON, OnCButton)
	ON_BN_CLICKED(IDC_D_BUTTON, OnDButton)
	ON_BN_CLICKED(IDC_E_BUTTON, OnEButton)
	ON_BN_CLICKED(IDC_F_BUTTON, OnFButton)
	ON_BN_CLICKED(IDC_TO_D_BUTTON, OnToDButton)
	ON_BN_CLICKED(IDC_TO_H_BUTTON, OnToHButton)
	ON_BN_CLICKED(IDC_TO_O_BUTTON, OnToOButton)
	ON_BN_CLICKED(IDC_O_RADIO, OnORadio)
	ON_BN_CLICKED(IDC_H_RADIO, OnHRadio)
	ON_BN_CLICKED(IDC_D_RADIO, OnDRadio)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEX_Calculator04Dlg message handlers

BOOL CEX_Calculator04Dlg::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
	
	m_AButton.EnableWindow(FALSE);
	m_BButton.EnableWindow(FALSE);
	m_CButton.EnableWindow(FALSE);
	m_DButton.EnableWindow(FALSE);
	m_EButton.EnableWindow(FALSE);
	m_FButton.EnableWindow(FALSE);

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

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

void CEX_Calculator04Dlg::On0Button() 
{
	// TODO: Add your control notification handler code here
	
int i_InputCheck=m_InputCheck.GetState();

	switch (char_radio)	{
		case 'O':
			value=value*8+0;
			str.Format("%o",value);
			if(i_InputCheck==1) str=str+"Q";
			break;
		case 'D':
			value=value*10+0;
			str.Format("%d",value);
			if(i_InputCheck==1) str=str+"D";
			break;
		case 'H':
			value=value*16+0;
			str.Format("%x",value);
			if(i_InputCheck==1) str=str+"H";
			break;
	}
	
	m_InputEdit=str;						//将输入数据显示在编辑框中
	UpdateData(FALSE);					
}

void CEX_Calculator04Dlg::On1Button() 
{
	// TODO: Add your control notification handler code here
	int i_InputCheck=m_InputCheck.GetState();

	switch (char_radio)	{
		case 'O':
			value=value*8+1;
			str.Format("%o",value);
			if(i_InputCheck==1) str=str+"Q";
			break;
		case 'D':
			value=value*10+1;
			str.Format("%d",value);
			if(i_InputCheck==1) str=str+"D";
			break;
		case 'H':
			value=value*16+1;
			str.Format("%x",value);
			if(i_InputCheck==1) str=str+"H";
			break;
	}
	
	m_InputEdit=str;						//将输入数据显示在编辑框中
	UpdateData(FALSE);
}

void CEX_Calculator04Dlg::On2Button() 
{
	// TODO: Add your control notification handler code here
	int i_InputCheck=m_InputCheck.GetState();

	switch (char_radio)	{
		case 'O':
			value=value*8+2;
			str.Format("%o",value);
			if(i_InputCheck==1) str=str+"Q";
			break;
		case 'D':
			value=value*10+2;
			str.Format("%d",value);
			if(i_InputCheck==1) str=str+"D";
			break;
		case 'H':
			value=value*16+2;
			str.Format("%x",value);
			if(i_InputCheck==1) str=str+"H";
			break;
	}
	
	m_InputEdit=str;						//将输入数据显示在编辑框中
	UpdateData(FALSE);
}

void CEX_Calculator04Dlg::On3Button() 
{
	// TODO: Add your control notification handler code here
	int i_InputCheck=m_InputCheck.GetState();

	switch (char_radio)	{
		case 'O':
			value=value*8+3;
			str.Format("%o",value);
			if(i_InputCheck==1) str=str+"Q";
			break;
		case 'D':
			value=value*10+3;
			str.Format("%d",value);
			if(i_InputCheck==1) str=str+"D";
			break;
		case 'H':
			value=value*16+3;
			str.Format("%x",value);
			if(i_InputCheck==1) str=str+"H";

⌨️ 快捷键说明

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