CframeWnd :: getActiveView functions

xiaoxiao2021-03-05  23

I use the VC6 Generation Wizard to generate a program that does not use the Document / View structure.

I looked at his structure carefully and found a function as follows (taken from the MFC source code):

BOOL CMainFrame :: OnCmdMsg (UINT nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO * pHandlerInfo) {// let the view have first crack at the command if (m_wndView.OnCmdMsg (nID, nCode, pExtra, pHandlerInfo)) {return TRUE } // OtherWise, Do Default Handling Return CFrameWnd :: Oncmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO);

When I started, I didn't understand this code because the oncmdmsg function was processed by the WM_COMMAND message. Refer to CFrameWnd :: OnCmdmsg, CView :: Oncmdmsg, CCMDTARGET :: OnCmdmsg, cdocument :: oncmdmsg. The flow route that seems to the entire WM_COMMAND message has been fixed, as follows:

(Photo taken from vckbase.com)

Part of the code for the cframewnd :: oncmdmsg function is as follows:

Bool cframewnd :: oncmdmsg (uint Nid, int Ncode, void * pextra, afx_cmdhandlerinfo * phandlerinfo) {cpushroutingframe push (this)

// pump through current view first cview * pView = getActiveView (); if (pView! = null && pview-> oncmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO) Return True;

// The Pump Through Frame IF (CWnd :: OnCmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO) RETURN TRUE;

// Last But Not Least, Pump Through App CWINAPP * PAPP = AFXGetApp (); IF (PAP! = Null && Papp-> Oncmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO) Return True;

Return false;}

CFRAMEWND :: OnCmdmsg and the above-mentioned picture, it seems that all WM_COMMAND messages come to CFrameWnd, first send this message to the view, that is, the view here is always higher than the CFrameWnd. Then in the cmainframe :: oncmdmsg function, it seems to use m_wndview.oncmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO) is not necessary, because cframewnd :: oncmdmsg (NID, NCODE, PEXTRA, PHANDLERINFO) function will first pass this message to VIEW is higher than his high priority.

So, how is it?

Later, after a common test, found that the cframewnd :: getActiveView function always returns NULL in a program that does not use the "Document / View" structure. This program happens to use the "Document / View" structure. The problem is here. CFRAMEWND :: OnCmdmsg function CView * pView = getActiveView () statement can only go to a null, so he can't send a WM_COMMAND message to View. So we must provide a M_WndView.oncmdmsg in cmainframe :: oncmdmsg (NID NCODE, PEXTRA, PHANDLERINFO, so you can send a WM_COMMAND message to View. This is the first article of the younger's work on MFC. In fact, there are many places that don't understand their own mechanisms. Many small experiments seem to be correct, but this is inevitable to have a mistake. Welcome everyone. Point out the wrong place. Now I am looking for information about the cframewnd :: getActiveView function, I hope that I have the idea. If the big brother knows that this function can return to the answer of the View under the "Document / View" structure, please tell me! Thank you.

Once again, this is a very correct article that is not necessarily correct, if there is a mistake, please point out, I must try it to keep it correct.

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

New Post(0)