Overview and basic use of MFC

1. Layout:

Add control, right-click control, attribute, must change: ID

2. Right-click the control, add an event handler (select a message event (click, etc.)), or double-click the control (click) to go to the slot function corresponding to the control message, or select an existing message in the class wizard (right-click) Then add the function; system message, you can select the message that comes with the system in the class wizard, message, and then click to add a handler (such as slider control, combo box control, etc.)

3. GetDlgItemTextW (ID); and SetDlgItemTextW (ID, CString object), you can get and modify the control text

4. There are two ways to use the control: (this-> ui-> control ID-> function can be used directly in qt, MFC is different)

(1) Right-click control, add variables, you can add a local variable of a control, through this variable you can call many functions of the control to achieve many functions. In the class wizard, select member variables, you can also add.

(2) With GetDlgItem (ID), you can get the pointer of the control, and then you can call the function of the control through this pointer.

5. MFC file structure (based on dialog box):

**. h, **. cpp This defines the derived class of CwinApp. The CwinApp class encapsulates the message loop mechanism of windows, and is responsible for the cleanup of application initialization and exit.

** Dlg.h, ** Dlg.cpp is used to create the interface, and the added variables will be in this class. There is an OnInitDialog function, // TODO: Add additional initialization code here, you can add some initialization stuff in this (it can be considered global)

6. The function of MFC is generally capitalized at the beginning

7. Some MFC functions have the same name as the windows API. When calling this kind of windows API, add:

8.MessageBox()弹窗

----------------------------------------------------------------------------------------------

Overview

The full name of MFC is Microsoft Foundation Classes, that is, Microsoft Foundation Class Library.

Microsoft has integrated a large number of APIs of the Windows operating system in the form of C ++ classes in MFC, and extended some classes such as CArray, CString, etc. In addition, MFC also includes a windows application development framework.

The following is a summary of the MFC development framework:

1.windows message mechanism

Each MFC program corresponds to a message loop. When the application starts, WinMain will start this message loop, constantly retrieving the messages sent by the operating system. When receiving messages from the operating system (mouse click, keyboard input, etc. events will The message that triggers the operating system), the message loop sends the message to the window process corresponding to the application, and the window process performs different processing according to the different types of messages.

 

2. All standard controls in the MFC framework are inherited from CWnd. To display the controls in your own style, you need to inherit the existing control class and redraw in the class you wrote. If you can find some others write it The MFC self-drawing control can also be used.

 

3. The MFC control uses CDC when drawing itself. CDC is a device description table. It virtualizes peripherals such as displays to CDC. When redrawing, you only need to operate the virtual logic plane of CDC. The operating system can map CDC to On the display.

 

4. The MFC framework can customize the message. The custom message can also transmit two parameters while sending the message. It is useful in projects with multiple threads or callback functions. You can also send messages when you need to update the control frequently. .

 

5. In addition to the existing standard controls, MFC also supports COM components, ActiveX controls, etc.

 

6. To use encoding-independent character constants in MFC, use _T macro, TCHAR for char type, LPTSTR for char *, and LPCTSTR for const char *.

 

7. MFC standard control

MFC standard controls can be dragged directly onto the interface. Each standard control can be bound to two types of variables: value types and control types. Value types are directly bound to the values ​​displayed by the control. In addition to the value of the control, you can also control the behavior and properties of the control.

UpdateData(TRUE)和UpdateData(FALSE):

UpdateData (TRUE) is to assign the values ​​displayed by all controls on the interface to its corresponding value type variables, and UpdateData (FALSE) is to refresh the value of a value type variable to its corresponding control and display it.

If you want to get or set the value of a control individually, you can use GetDlgItemText, GetDlgItemInt, SetDlgItemInt, SetDlgItemText and other functions that interact with the control through the control ID.

 

8. MFC cannot cross platform, Qt can

 

 

 

Reference: https://blog.csdn.net/qq_26164563/article/details/80928825

---------------------------------------------------------------------------------------------------------------------------------------------

Controls

button

edit control text edit box

combo box drop-down list options

check box multiple choice

Radio button radio

scroll bar (the kind in word)

progress control progress bar,

spin control value increase and decrease bar, generally used with edit control

slider control (add event processing messages to be selected in the system-defined messages, not double-click) (add variables, such as m_slid, and m_slid.GetPos can get the position, this can be written in the previous message processing function. m_slid.SetRange (1,100), this is to set the value range of the scroll bar, this can be written in the initialization function)

hotKey hotkey, you can automatically get the keys entered by the keyboard

list control list

tree control

rich edit control Rich text box, the difference with edit control is that the font inside is formatted, there can be multiple formats. So you can use the button to change the font format in this control

tab control Tab interface, similar to the toolbar. Click a button to change the interface. The interface should be in the resource view, right-click Dialog, add Dialog, an interface will appear, then add the class, and then bind

---------------------------------------------------------------------------------------------

The CString class is a commonly used string type in MFC. The parameter of a general function is a string of CString. It has many methods and functions, similar to QString in Qt

CString str;

int num = 1 ;

str.Format (L "The serial number is:% d", num);

--------------------------------------------------------------------------------------------

BYTE is a byte, that is, 8 bits. Used to store char or char type pointer.

WORD is a word, that is, 16 bits. Used to store 16-bit integers or 16-bit addresses.

DWORD is a double word, which is 32 bits. Can be used to store 32-bit integers or 32-bit memory addresses .

Mainly for convenience when writing and reading the source code. They are defined in the windef.h header file.

  typedef unsigned char BYTE

  typedef unsigned short WORD;

  typedef unsigned long DWORD

 

 

 

 

Published 59 original articles · Likes46 · Visits 30,000+

Guess you like

Origin blog.csdn.net/sinat_41852207/article/details/86675928