CDialog's derived class inok () functions and Virtual relationships

zhaozj2021-02-16  50

CDialog's derived class inok () functions and Virtual relationships

After inserting a dialog, create a class named CMYDIALOG, derive from CDialog; when adding dialog resources, a button is automatically generated, we can add a deemed handler to an overok (); Onok () in myDialog.h declaration is Virtual void onok (); if we add a button on the dialog, the default ID is IDC_Button1, we can add a deactivated handler to ONBUTTON1 (); onButton1 () Declaration in MyDialog.h is AFX_MSG Void onButton1 (); there is a message mapping macro in myDialog.cpp: ON_BN_CLICKED (IDC_Button1, OnButton1)

Why is the message mapping function of the button, onButton1 () and onok () implementation have such a big difference? Because the CDIALOG is used as a special button for the buttons for the IDOK, it is necessary to exchange DODATAEXChange (). (This is another interesting topic. According to my experience, many people have known to do DodataExchange () is known, I don't know if it is, I have time in the future post.

However, in fact, the message mapping of the IDOK button is followed by the same processing path as the ordinary button IDC_Button1:

If tracking cDialog :: Onok (), we entered DLGCore.cpp, which is CDIALOG implementation file, which can be found in the message mapping table in CDialog, actually ON_BN_CLICKED message mapping macro is also processing WM_COMMAND message, so the role of both; then enter AFXWIN.H, this is CDIALOG's declaration file, which can be found in CDialog ();

Ah! We finally knew the 来 龙 去 去! That is, in the base class, it is implemented using a normal message mapping, just declares it as a Virtual function in the base class, so that the ONOK () function in CMYDIALOG can be called!

Small tips:

How to enter AFXWIN.H? Enter cDialog in the VC program, right click, select the Go to definition of cdialog in the pop-up menu, or the keyboard cursor is positioned in any location in CDialog, press ; why AFX_MSG void onbutton1 () declares has AFX_MSG, and No onok ()? ? Please use the F12 method to track AFX_MSG this strange function modifier declaration: #ifndef AFX_MSG # Define AFX_MSG // INTENTIONAL PLACEHOLDER # ENDIF, what is it? ! Adding this stuff before all the message mapping functions, it is said to be an extension in the future, which may later be a special indication message mapping function. But C # is from, .NET Framework Library replaces the trend of MFC seems to be inevitable ... Is there a new day after our AFX_MSG?

转载请注明原文地址:https://www.9cbs.com/read-19894.html

New Post(0)