Microsoft FoundaTIon Classes (MFC) is a class library provided by Microsoft, which encapsulates the Windows API in the form of C++ classes and includes an application framework to reduce application developers. The amount of work. It contains a large number of Windows handle wrapper classes and many wrapper classes for Windows built-in controls and components.
MFC (Microsoft FoundaTIonClasses) is the abbreviation of Microsoft Foundation Class Library. It is a C++ class library implemented by Microsoft Corporation. It mainly encapsulates most of the windows API functions. vc++ is the integrated development environment of c/c++ developed by Microsoft Corporation. The so-called integrated development environment That is to say, it can be edited, compiled, debugged, and used instead of using multiple tool rotation operations, which is more flexible. Vc also refers to its internal compiler, the integrated development environment must have a compiler kernel, such as DevC++, one of the compiler kernels is gcc.
In addition to being a class library, MFC is still a framework. In the vc++ project, a new MFC project will be created. The development environment will automatically generate many files for you, and it uses mfcxx.dll. Xx is the version, it encapsulates the mfc kernel, so you can't see the message loop in the original SDK programming in your code, etc., because the MFC framework helps you package it, so you can concentrate on your program. Logic, not something that is repeated every time, but because it is a generic framework, there is no best targeting, and of course some flexibility and efficiency are lost. However, the MFC package is very shallow, so there is little loss in efficiency.
MFC Beginner CourseWrite MFC program, in fact, like writing a C++ program, create a new project on the VS build platform, and then always default to the next step, but there are other requirements that need to be added according to the actual situation. After building a project, two interfaces will appear, one is the display window and the other is the programming interface, similar to the front panel and block diagram in LV. There is a toolbox on the right side of the interface that you can add as needed.
The following is mainly to write a simple calculator program to achieve four operations on the input number, the main steps are as follows:
1. Place 6 button controls and 3 edit box controls in the dialog box.
Specific operation: Click the toolbox on the right side of the interface to select specific controls according to specific needs.
2. Add the three edit box controls to the float variable m_edit1, m_edit2, and m_edit3.
Specific operation: Select the edit box and right click to add the variable, change the right category to value, and change the variable name to m_edit1, m_edit2, m_edit3.
3. Rename the 6 button controls
Specific operation: Select the button and click the right-click property to change CapTIon to the desired + - * / clear and close, specifically named as needed.
4. Select the Group Box in the toolbox to frame the four operations, then change the name by attribute and add static text (StaTIc Text) to edit the name.
The main part of the interface is completed, the next step is to write the code, double-click each control, you can automatically jump to the program writing part, the main code is as follows
[html] view plain copyvoid CMFC Getting Started Dlg::OnBnClickedButton1()
{
// TODO: Add control notification handler code here
UpdateData (true); / / get data from the control assigned to the variable
M_edit3 = m_edit1 + m_edit2;
UpdateData (false) ;/ / output variable value to the control
}
Void CMFC Getting Started Dlg::OnBnClickedButton2()
{
// TODO: Add control notification handler code here
UpdateData(true);
M_edit3 = m_edit1 - m_edit2;
UpdateData(false);
}
Void CMFC Getting Started Dlg::OnBnClickedButton3()
{
// TODO: Add control notification handler code here
UpdateData(true);
M_edit3 = m_edit1*m_edit2;
UpdateData(false);
}
Void CMFC Getting Started Dlg::OnBnClickedButton4()
{
// TODO: Add control notification handler code here
UpdateData(true);
If (m_edit2 == 0)
{
MessageBox (_T ("Divisor cannot be 0"));
Return;
}
M_edit3 = m_edit1 / m_edit2;
UpdateData(false);
}
Void CMFC Getting Started Dlg::OnBnClickedButton7()
{
// TODO: Add control notification handler code here
M_edit1 = 0;
M_edit2 = 0;
M_edit3 = 0;
UpdateData(false);
GotoDlgCtrl((CEdit*)GetDlgItem(IDC_EDIT1));//Set the focus in the first edit box
}
Finally, the writing is completed, run it, and an interface pops up as follows:
To verify the program, take the addition as an example. m_edit1 enters 18 and m_edit2 enters 36. The result is as follows.
Twinkle System Technology Co Ltd , https://www.pickingbylight.com