Introduction to MFC, QT, winform, and WPF

Source: Internet
Author: User
Document directory
  • Composition of programming languages
  • Gui importance
Composition of programming languages

Programming languages are similar to natural languages in English. when learning English, we know that we should first remember 26 letters, then words and their pronunciation, followed by phrases and sentences. simply put, you can remember words and be familiar with lexical and syntaxes. the next step is the application. many people who use the same language have a translator who can translate their ideas into languages and then express them in words or words, listening and reading translate the received language into the thoughts that the brain can understand.

Then, the programming language first develops some words like English, and then lexical and syntaxes. type keywords such as int and char, or some other keywords are words. but such language machines do not know. so we need a compiler to translate it into 01 strings that computers can recognize. the compiler is like a translator in the brain. so simply put, adding a compiler to some syntax rules can mark the emergence of a new programming language. however, the built-in functions of the language are very basic operations. You need to write a lot of code to implement complicated functions, so some people write code for a lot of common operations first, and you just need to call it later. make a lot of wheels for you to use. this is to develop some libraries for you to call. in object-oriented languages, class libraries are generally called stacks of classes. if the library is powerful enough, we can also call it a framework. anyway, we can simply understand the framework as some powerful and closely linked class libraries.

MFC and QT are common GUI frameworks in C ++, while winform and WPF are common frameworks in C #. However, we rarely call them winform frameworks, it may be called the graphical control class library more points. it's just a name. in addition, winform and WPF (Windows form and Windows Presentation Foundation for desktop application development on Windows) only provide a bunch of GUI class libraries, in addition to a bunch of GUI class libraries, MFC and QT also provide many other classes. more powerful.

 

Gui importance

GUI is graphical user interface (graphical user interface ). many people may think that the whole pages are not technically competent. but in fact, many users do not know how to write your background code. what they see is only the UI. They feel that the page looks comfortable and the performance is not very poor. In a professional word, the user experience is good. That is a good software product. one of the most important reasons why Apple products are so popular is that the UI is beautiful and cool. when we develop a software product, if we stand in the developer's Perspective (the site may be different from other perspectives) a software is nothing more than saving data, processing data, and some logical operations between data, then interact with the user through a friend's UI (of course there are a few background software that do not need the UI ).

We know that various design modes are full of sky and varied, but the most well-known is the MVC model (model, view, Controller ). model + controller is the data processing component, and view is the UI interface. in fact, QT, MFC, winform, and WPF are equivalent to the simplified MVC mode, from three layers to two layers. model + controller is not differentiated. the view layer is developed independently. The separation between the UI and the logic processing code of the data makes it clear and easy to understand and maintain. more importantly, many UI controls are well-prepared. You can't use them directly.

In addition, you may have heard of STL (standard template library). The standard template library is equivalent to calling common data structures and Data Operations (algorithms, it is equivalent to implementing the data structure and algorithm into common code for you to call.

 

Why should we put these four frameworks together, because there was something similar before the four. There is no doubt that the frameworks of the same language are similar, but in fact there are similar libraries between different languages. the MFC in C ++ is a little similar to winform in C #, while the QT in C ++ is a little similar to WPF in C #.

 

MFC and winform

The above four frameworks are simplified two-layer MVC models. the logic processing of data in MFC is naturally put in files with the suffix H and CPP. the pile of resources related to the page is stored in the file with the RC suffix. generally, a project corresponds to an RC file, but multiple projects can share one RC file. of course, in the development environment of Vs, all page controls will not be heap together because all information is stored in the RC file. in the resource view, we can see separate dialog. Each dialog is a page containing buttons and other controls. of course, resource files can also be stored in other resources such as string table and bitmap. if you view the code in the RC file, there are a bunch of begins.
The content is naturally some of the properties of the control. The code syntax has nothing to do with the c ++ standard syntax, and I don't know what the syntax is.

The UI Layer is separated. If the code that processes the data logic needs to interact with the UI, the resource ID is associated. for example, many classes can share a dialog page. Of course, most of the time we use a class to correspond to a dialog. it is inconvenient for the UI page in MFC to interact with the background code. for example, to map a widget (such as button and ComboBox) to a variable, you must write some code in the dodataexchange function to associate it. if the key button needs to correspond to any operation, it must be associated through a macro such as begin_message_map. messages sent from a widget correspond to a function. of course, because all controls inherit from the cwnd class, you can also directly operate controls through some of these functions, such as functions such as getdlgitem, just pass the resource ID as a parameter.

Some Ideas of MFC are also left behind in winform, such as resources. the resx file usually contains the image information, and then setting. settings is similar to the string table in MFC. however, these functions are rarely used in C. page controls are no longer stored in resource files. in winform, object-oriented is used. Data logic processing code and UI code are in the same class, except that C # has the concept of sub-class, that is to say, the code of the same class can be separated in several files. if there is a window class formarwen, the data logic code is placed in formarwen. in the CS file, put the UI code in formarwen. designer. CS file. however, the class definitions in these two files must be written in partial.
In class formarwen, the keyword partial is a unique keyword in C #. It is used to represent a partial class. A class can be defined in multiple files. the UI code here is also completely standard C # code, unlike the lack of readability of the MFC resource file. you can also copy the UI code to the data logic code.

Each control in the window has a name, which is equivalent to the resource ID in MFC. Then you can directly use this name when calling the control in the code, which is equivalent to a variable name. therefore, code interaction with the UI is very convenient. In addition, the message mechanism in MFC is encapsulated as an event here ), you can select any control and click any event on its propterties event page to automatically generate a class, you can directly write the Event code to be processed in the class. this actually simplifies the complex message mechanism in Win32 API into an event, which is convenient for users and does not need to worry about the complex logic behind it. although MFC encapsulates the message mechanism, the encapsulation is not good enough.

Therefore, compared with MFC, winform makes interaction between the UI code and the data logic processing code easier, clearer, and easier to understand. some of the complex details behind the scenes are encapsulated without user intervention. in addition, the UI control is more powerful and looks more beautiful.

 

 

QT and WPF

The same as the C ++ GUI framework, QT is not so similar to MFC, and the logic is closer to the C # WPF framework. first, not all UI-related code is integrated into an RC file like MFC, but a UI page has an XML file with a suffix of UI. the data logic processing code is stored in H and CPP files. and all three of them have the same name. if you want to interact with the control, it is as convenient as WPF. Each control has an objectname, which is equivalent to the resource ID number of MFC. Then you can directly use this name when calling the control, of course, you must add a pointer to your own class. for example, if there is an Arwen class and a button is named BTN, it is generally the first Arwen *
Ui; then UI-> BTN is the same as using this. BTN in WPF, but the This prefix in WPF can be omitted.
In addition, there is no message processing concept in MFC in QT, but is encapsulated into a mechanism called signal/slot. this is very similar to the winform event in C #. For example, you can right-click a button in QT and right-click go to slot to select a signal, it is equivalent to various types of events in C #. Of course, there must be fewer signal events. the slot is the corresponding processing function of the event.

WPF is also a file corresponding to a UI page and suffixed with XAML. The full name of XAML is eXtensible Application Markup Language. we can regard it as a special XML file. the UI file in QT is a standard XML file. then other code unrelated to the UI is put in the XAML. CS file.

 

It should be said that winform is the easiest to understand from the perspective of our habits of thinking. The code corresponding to the UI page is completely standard C # code. the RC file corresponding to the MFC page, the XML file corresponding to the QT page, and The XAML file corresponding to the WPF page are not standard C ++ or C # code. it is not in line with our habits of thinking.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.