MainFrame Dlg, App, Doc, View of relations in MFC

The MainFrame : main frame class

Dlg is an abbreviation Dialog represents the dialog itself

 
App class is this SDI as the entry "program", a bit like Main function c, which is not derived from the CWND out. App represents the application itself.

 
View a view class is responsible for displaying data, providing data editing, modifying function data. It refers to the editing area inside the thing is the middle piece of the white area, responsible for drawing and respond to some messages

 
Doc indicates that the document class, providing save and load the data. When a bit like a database, save the edited data, for Redraw view of the use, and save the file.

 General dynamic editing data are placed inside Doc. He is not derived from the CWND, there is no inheritance MessageBox function can be used AfxMessageBox function.

 

 

1) In the View obtained in Doc pointer       

  2)    In App obtained in MainFrame pointer    

  3)    In the View obtained in MainFrame pointer    

  4)    obtaining View (established) Pointer    

  5)    to obtain a pointer to the current document    

  6)    to obtain the status bar and toolbar pointer    

  7)    to obtain the status bar and toolbar variables    

  8)    In Mainframe obtained Menu Pointer    

  9)    obtained in any application class class    

  10)    obtaining a pointer from view class document class (1)    

  11)    In App obtain a document template pointers    

  12)    to obtain the document from the document template class pointer    

  13)    to obtain the document template pointers in the document class    

  14)    obtaining a pointer from the document view class category (2)    

  15)    obtaining a pointer from another view of a view class class    

     

  VC programming for students just beginning to learn, the biggest problem is the obstacles and get the message mechanism and pointer operations. In fact, these are basically content per copy VC learning tool will be talking about content, but also through MSDN can solve many problems. The following text mainly some personal experience in programming pointers, saying the wrong place, please correct me. General framework we are using the VC provides Wizard -generated MFC App Wizard (exe) framework, whether it is a single or multi-document document, there are pointers acquisition and operational problems. The following section is primarily aimed at the general framework, and then repeat that multi-thread pointers. The need to use the class header file containing the response. First, this type generally obtained ( depending on the document, the dialog support ) instance pointer this , with this purpose, can send a pointer to the other main class or function by a function of the class, so that in operation and use of this class of non- this class functions. 

    1 ) In the View obtained in Doc pointer       

CYouSDIDoc * pDoc = GetDocument (); a view can have only one document.    

    2)    In App obtained in MainFrame pointer    

  CWinApp    in    m_pMainWnd variable is MainFrame pointer    

  It may be:    the CMainFrame Pmain * = (the CMainFrame *) AfxGetMainWnd (); 

    3)    In the View obtained in MainFrame pointer 

  CMainFrame   *pMain=(CmaimFrame   *)AfxGetApp()‐>m_pMainWnd; 

    4)    obtaining View (established) Pointer 

  CMainFrame   *pMain=(CmaimFrame   *)AfxGetApp()‐>m_pMainWnd;    

  CyouView   *pView=(CyouView   *)pMain‐>GetActiveView(); 

    5)    to obtain a pointer to the current document 

  CDocument   *   pCurrentDoc   =(CFrameWnd   *)m_pMainWnd‐>GetActiveDocument(); 

    6)    to obtain the status bar and toolbar pointer 

  CStatusBar   *   pStatusBar(CStatusBar   *)AfxGetMainWnd()‐>GetDescendantWindow(AFX_IDW_STATUS_BAR);    

  CToolBar   *   pToolBar=(CtoolBar   *)AfxGetMainWnd()‐>GetDescendantWindow(AFX_IDW_TOOLBAR);    

    7)    If the frame added to the tool bar and status bar can be so variable      

  (CMainFrame   *)GetParent()‐>m_wndToolBar;    

  (CMainFrame   *)GetParent()‐>m_wndStatusBar;    

    8)    In Mainframe obtained Menu Pointer 

  CMenu   *pMenu=m_pMainWnd‐>GetMenu(); 

    9)    obtained in any application class class    

  With MFC global function ) AfxGetApp ( obtained.    

  10)    obtaining a pointer from view class document class    

  I am from http://download.cqcnc.com/soft/program/article/vc/vc405.html learned,    

  View class pointer to get the document from the general purpose to control the positioning of multiple views of the same document, my experience    

  In particular word processing CEditView when generating a plurality of views based, this feature is highly desirable.      

  CDocument class provides two functions for the positioning of the view class:    

  GetFirstViewPosition()GetNextView()      

  virtual   POSITION   GetFirstViewPosition()   const;    

  virtual   CView*   GetNextView(POSITION&   rPosition)   const;    

     

  Note: GetNextView () parentheses are reference parameters, and therefore the execution value may change.    

  GetFirstViewPosition () to return to the first position of a view (the view class pointer is not returned, but a    

  A POSITION type value), GetNextView () has two functions: Returns a pointer to the next class of view and with    

  Called by reference to changes in the incoming POSITION value type parameter. Obviously, in the Test program, only    

  A view class, so only these two function calls once obtained CTestView pointer follows (to be fixed    

  A righteous POSITION structure variable to assist the operator):      

  CTestView*   pTestView;    

  POSITION   pos=GetFirstViewPosition();    

  pTestView=GetNextView(pos);    

     

  This makes it possible to CTestView pointer class pTestView. After performing a few, variable pos = NULL, because no    

  There is a next view class, naturally, did not view the next class POSITION. But this is too simple a few sentences, not    

  Having too versatility and safety features; when as said earlier, when the return to view of a plurality of means    

  When given a pointer type, we need to traverse all the view class until you find designated class so far. Refers to a class pointer Analyzing    

  When the instances of a class if available IsKindOf () member function to check the line, such as:    

    pView‐>IsKindOf(RUNTIME_CLASS(CTestView));    

  You can check pView whether the meaning is CTestView class.    

     

  With the above basis, we are able to make any kind of pointer from the document class. For convenience, we will make it    

  Function as a member of a class of documents, takes one argument, a pointer indicating which class you want to get. To achieve the following:      

      

  Wherein using the member functions of the view class two IsKindOf () to determine, because the exit while loop has three    

  may:    

     

  1.pos is NULL , i.e., has a view of the class does not exist for the operator;    

  2.pView already meet the requirements.    

     

  1 and 2 the same are met. This is because GetNextView () function is to change the current view to a view of the pointer    

  It returns the current view position while the pointer, thus pos is pView next class of view POSITION, fully    

  There may be both pos == NULL is pView meet the needs. When the desired final view is a view of a final    

  As the lead when a view class. Analyzing therefore required the use of two.    

  Using this function should follow the format (to obtain CTestView pointer as an example):    

  CTestView*   pTestView=(CTestView*)GetView(RUNTIME_CLASS(CTestView));    

  RUNTIME_CLASS is a macro that can be simply understood its role: the name of the class into    

  CRuntimeClass pointer. As for the cast but also to consider the security features, because from the same    

  Pointer type between the base class is compatible with each other. This casts and perhaps unnecessary, but it can avoid a    

  Some trouble may arise.    

     

  3. obtain another view of the pointer from a class view of the class synthesis 1 and 2 , it is easy to draw each other to obtain the view class       

  Method pointers: document class is used as a relay, first with 1 to obtain a pointer to the document class method, then 2 method,    

  Positioning function to view the document class get another view class. Similarly, a function may be implemented as:    

  (Assuming from CTestAView acquires class pointer to other views)    

   This function and 2 in GetView () compared to the first sentence of the first, and more to get the document class pointers, the second is    

  GetFirstViewPosition () and GetNextView () before adding the document class pointer, to indicate that they are a document    

  Class member functions. With this function; from when CTestAView acquires CTestBView pointer, just as    

  下:CTestBView*   pTestbView=(CTestView*)GetView(RUNTIME_CLASS(CTestBView)); 

 

ON. Posted 2011-11-17 16:51 the On at The Way reading ( ... ) Comments ( ... ) edit collections

Reproduced in: https: //www.cnblogs.com/areliang/archive/2011/11/17/2252901.html

Guess you like

Origin blog.csdn.net/weixin_34177064/article/details/93610000