Вставил, но эффекта не вижу. Появилось три warning`а... Ниже весь код диалога. Тупо и длинно. Уверен, что можно обработать сразу всю группу цифровых клавиш через индекс в группе
// calcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "calc.h"
#include "calcDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCalcDlg dialog
CCalcDlg::CCalcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCalcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCalcDlg)
m_edit1 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCalcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCalcDlg)
DDX_Control(pDX, IDC_BUTTON0, m_bn0);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCalcDlg, CDialog)
//{{AFX_MSG_MAP(CCalcDlg)
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_BUTTON10, OnButton10)
ON_BN_CLICKED(IDC_function1, Onfunction1)
ON_BN_CLICKED(IDC_function2, Onfunction2)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_BUTTON11, OnButton11)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCalcDlg message handlers
BOOL CCalcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
}
// 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 CCalcDlg::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 CCalcDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCalcDlg::OnButton0()
{
m_edit1=m_edit1+"0";
UpdateData(false);
}
void CCalcDlg::OnButton1()
{
m_edit1=m_edit1+"1";
UpdateData(false);
}
void CCalcDlg::OnButton2()
{
m_edit1=m_edit1+"2";
UpdateData(false);
}
void CCalcDlg::OnButton3()
{
m_edit1=m_edit1+"3";
UpdateData(false);
}
void CCalcDlg::OnButton4()
{
m_edit1=m_edit1+"4";
UpdateData(false);
}
void CCalcDlg::OnButton5()
{
m_edit1=m_edit1+"5";
UpdateData(false);
}
void CCalcDlg::OnButton6()
{
m_edit1=m_edit1+"6";
UpdateData(false);
}
void CCalcDlg::OnButton7()
{
m_edit1=m_edit1+"7";
UpdateData(false);
}
void CCalcDlg::OnButton8()
{
m_edit1=m_edit1+"8";
UpdateData(false);
}
void CCalcDlg::OnButton9()
{
m_edit1=m_edit1+"9";
UpdateData(false);
}
void CCalcDlg::OnButton10()
{
m_edit1="";
UpdateData(false);
}
void CCalcDlg::Onfunction1()
{
char buffer[20];
m_edit1=ltoa(tan(atol(m_edit1)),buffer,10);
UpdateData(false);
}
void CCalcDlg::Onfunction2()
{
char buffer[20];
m_edit1=ltoa(sqrt(atol(m_edit1)),buffer,10);
UpdateData(false);
}
void CCalcDlg::OnChangeEdit1()
{
//ainoaou oeacaoaeu ia aaeo:
CEdit* pEd=(CEdit*)GetDlgItem(IDC_EDIT1);
//ainoaou oaeno ec aaeoa
CString txt;
pEd->GetWindowText(txt);
//niio?ei, aaa eo?ni?
int nCurrPos1,nCurrPos2;
pEd->GetSel(nCurrPos1,nCurrPos2);
if(nCurrPos1)nCurrPos1--;
//caiaiyai oi?ee ia caiyoua (iioeiiaeuii)
txt.Replace(".",",");
//euai ia?ao? caiyoo?
int nFPos;
nFPos=txt.Find(',');
if(nFPos>=0)
{
//oaaeyai ana caiyoua, e?iia ia?aie
if(txt.Replace(",","")>1)
{
txt.Insert(nFPos,',');
pEd->SetWindowText(txt);
pEd->SetSel(nCurrPos1,nCurrPos1);
}
}
}
void CCalcDlg::OnButton11()
{
m_edit1=m_edit1+",";
UpdateData(false);
}
Compiling...
calcDlg.cpp
c:\program files\microsoft visual studio\myprojects\calc\calcdlg.cpp(4) : warning C4652: compiler option 'Generate Browser Info' inconsistent with precompiled header; current command-line option will override that defined in the precompiled header
c:\Program Files\Microsoft Visual Studio\MyProjects\calc\calcDlg.cpp(181) : warning C4244: 'argument' : conversion from 'double' to 'long', possible loss of data
c:\Program Files\Microsoft Visual Studio\MyProjects\calc\calcDlg.cpp(188) : warning C4244: 'argument' : conversion from 'double' to 'long', possible loss of data
Linking...
calc.exe - 0 error(s), 3 warning(s)