Software development tools: VS2010
A project in the previous period needs to display the temperature value, you need to calculate the thermistor end ADC sampling value and temperature of the one by one correspondence, because of the large amount of calculation, think of their own write a simple calculator convenient calculation. In this code process, you need to process the edit data input, because the number of calculations is greater than 0, I only realized that edit can only enter numbers and decimal points of the function.
1, add a C + + class, inherits the base class Cedit,eg:class Cmyedit:public CEdit
2. Provide a message map to process messages, add in Myedit. h:
where Declare_message_map () is not followed by a semicolon.
Class Cmyedit:public CEdit
{public
:
cmyedit (void);
~cmyedit (void);
Implement
protected:
afx_msg void OnChar (UINT nchar,uint nrepcnt,uint nflags);//Declaration Message
Declare_message_map ()
};
3, then define the Myedit of the class member function. CPP file, use the BEGIN_MESSAGE_MAP () macro and the End_message_map () macro to implement the processing of the message.
where Begin_message_map (parameter 1, argument 2), Parameter 1 is the class name of the class, and Parameter 2 is the class name of the class base class.
Begin_message_map (Cmyedit, CEdit)
On_wm_char ()
End_message_map ()
4, and then specific implementation of message processing
void Cmyedit::onchar (UINT nchar,uint nrepcnt,uint nflags)
{
CString str;
if ('. ' = = NChar);//decimal point can only be entered once
{
getwindowtext (str);
if ("" = = str)
{
}
else if ( -1!= str. Find ('. '))
{
}
else
{
Cedit::onchar (nchar,nrepcnt,nflags);
}
}
else if ('-' = = NChar)//'-' process
{
}
else if (' 0 ' <= nChar && ' 9 ' >= NChar) | | (0x08 = = NChar) | | (0x2e = = NChar)) Number, BACKSPACE, delete key processing
{
Cedit::onchar (nchar,nrepcnt,nflags);
}
else <span style= "font-family:arial;" >//Other processing </span>
{
}
}
5, in * *. DLG.C, add
#include "MyEdit.h"
cmyedit my_edit1;
6. Add in **dlg.cpp
void **dlg::D odataexchange (cdataexchange* PDX)
{
CDialogEx::D odataexchange (PDX);
DDX_Control (PDX,IDC_EDIT1,MY_EDIT1);
}