     MFC 

           MFC-.   
 ,         
    .  ,      
    MFC.     
 MFC,   MFC-,  ,     . 
     MFC,     . 

    23 

           Windows,     
        .    
,  ,    MFC,    
   ,   , ,  . 
,       ,    
   . 

      MFC 

         1,  MFC   , 
   C++.     . 2.1.   
   CObject.    ,  
     ,  ,  
     ,      
.   CObject   , 
        (   
)    (    
).      ,   
CObject,     , ,   .   
       MFC,   
    . 
     . 2.1 ,       
CObject.       CCmdTarget, CFile, 
CDC, CGdiOb-ject, CException  CMenu.  CCmdTarget   
 .  ,   1   ,  Windows 
     ,     
  CCmdTarget.  CFile     ,  
    .  CDC    
   (     ). 
      ,   ,   
     (  ). jBjToj  
      (   
)  . CGdiObject      
GDI-.        
Windows,        
  ,   ""  "".  CException 
    , a CMenu    . 
 ,    ,  
  CObject     ,  
     , ,     . 
      CCmdTarget    : CWnd.   
     ,   ("")  
 ,      .   
 ,   CWnd,  CFrameWnd.   
   SDI- (SDI  Single Document Interface   
 ).       

    24      MFC:   

    Windows-.    ,       
      .  ,   
CFrameWnd,   2?^    (    
- ).	'                   -.'. 
     ,   CCmdTarget,  CWinThread.   
   ~    
 .       
 . 
     CWinThread , ,     
, q6jgaiuemjej<   -^ : 
CWinApp.          MFC,   
      ,    
  .  ,    , 
,    . ^_  
  ( _)   CWinApp.     
,   . 
     ,    ,     
   MFC. , ,     
.     Windows   MFC, 
     . 
        ,    .   
,         Windows. 
 ,          . 

    -  MFC 

     ,   MFC-,   
-?__,   .   : 
        ,   ,  ShowWindow()  
   CWnd. 
                TextOut()  
  CDC. 
             
CBitmap::LoadBitmap().      1,   API 
( Win32  Winl6)   - MFC.     
   .   ,    
    API-.     
   -. 

    2.  MFC	25 

      
    CDocument 
     
     
    CWinApp 
    COIeControtModuIe 
      
    CDocTemplate 
    COIeDocument COIeLinkingDoc :COIeServerDoc 
    CRichEditDoc 
    Single DocemplatefMu It iDocTem plate COIeObjectFactory 
    COIeTemplateServer 
      
      CException  Archive Except ion 
    !pj^!Egggptbji...  
    iCDBException 
    'CFileException 
    CDocltem 
    COIeCtientltem 
     CMemoryException 
    ______J 
    COIeDate^urce^^l COteDropSource	[ COIeDropTarget I 
    CRichEditCnlrltem 
     OLE- 
    COIeServerltem 
    gpleMessageFllter CCpnneciionPoInt   CWnd 
     OLE- 
    iCNotSupportedExceptionl ' COleException______I ICOIeDispatchExceptlonJ 
CResourceException | iCUserException ____I 
      
    CTTameWnd_______j 
    '?5f?Hli!2^2i__  MDI- 
    V 
    CMDIFrameWnd 
     MDI- 
    CMiniFrameWnd 
     SDI- 
    iCptelip^^^^^^ 
       
    CControlBar     _____ ;CDialogBar  COleResizeBar___ 
    CStatysBar    ____ 
    CToolBar 
    si^E^^ZZZIZ 
      CPropertySheet      __ 
     
     	\ 
    ?2iaJo?___J	^ 
    CCofnmonDialog        "	I 
    ^J CnieDialog	j CFindReplacePialog | CFonlDialog 
    COIeDialog _______ ^COIeBusyDialoQ ^^^| COIeChangelconDialog J 
COieChangeSqurceDjajogJ CpleConyertDialgg J COIelnsertDialog___] ; j ; COIeLinksDialog____1 
    COIeUpdateDialog COIePasteSpecialDialggj COIePrgpertlesDlalog     ! 
CPageSetupDialog         | CPrintDialog	___I 
    ^COIePropertyPage 
    CPropertyPage 
       
      
    CVjew 
    'CCtrMew________j CEdHVi^________| CListView_______ CRichEditVie^r'      ^ CTreeView 
    !CScrollView   _____j 
        
    CFqrmView_______ 
       
    CDaoRecgrdyiew_   _ CRecordView_____ 
        


    26 MFC:   


    ,    CObject 
       CFile	\      J    V j fcGdiObject      
               |	   f   -/ ' '  CArray (template)	  	V 
    :   CMemFile	j     i       CBitmap	j     >   CByteArray	CArchive	1 
    jCOIeStreamFile	I             CBrush	J     ; iCDWordArray	CDumpContext	1 
    CSocketFile	j              CFont	I         icdbArray	CRuntirneClass	1 
    !CStdioFile	i              CPalelte	1        ;CPtrArray	  	V 
     	!      CPen	j         i CStringArray	CPoint 
    :CDC	j                :CRgn	|        ICUIntArray	CRect 
    ,   i fcClientDC	J          	:,  t ' , CWord Array	CSize 
    ;   i {CMetaFiieDC	]        ;CMenu                              J	**       
 ,	CString 
    i jCPaintDC	i _ [          ODBC	       : 	CTime 
    fcWindowDC	|         CDatabase                      j		. /      CTimeSpan 
     	, ,'  'CRecordset                    |	CList (template)		v 
    ClmageList	 j                    
	CPtrList	CCommandLinelnfo CCreateContext 
    CLongBinary                      |	iCStringList	CFileStatus 
     	 ,	CMemoryState 
    CDaoDatabase                j	 	CPrintlnfo 
    ............                                                    
)	CDaoOueryDef                [		 	V 
    ***.                      i CAnimateCtrl 
jCButton iCBitmapButton	'y'       CDaoRecordset              j iCDaoTableDef   
              j CDaoWorkspace             | ^J          	 [ 
(template) ICMapWordToPtr CMapPtrToWord	CCmdUI CDaoFieldExchange CDataExchange CFieldExchange 
    CComboBox CEdit CHeaderCtrl ICHotKeyCtrl	CSyncObject                    i 
CCriticalSection            _J CEvent CMutex	CMapWordToOb CMapStringToPtr 
:CMapStringToOb	COIeDataObject COIeDispatchDriver CPropExchange CRectTracker 
    CListBox	CSemaphore		CWaitCursor 
    CCheckListBox	                          (	,   '   , 		i 
    :CDragListBox	           CAsyncSockel                 j	*        
	 CTypedPtrArray             | 
    CListCtrl	CSocket		CTypedPtrList                   | 
    | CProgressCtrl 
     OLE-	V 
    CFontHolder                   J 
    jCScrollBar                      v			CPictureHolder                | 
    ;CSIiderCtrl 
    ;CSpinButtonCtrl			OLE-	,/ 
    ;CStatic			COIeCurrency                   j 
    ;CStatusBarCtrl			COIeDateTime      ____ j 
    CTabCtrl			COIeDateTimeSpa         J 
    jCToolBarCttl			COIeVariant                      | 
    iCToolTipCtrl			 
    iCTreeCtrl			CMultiLock                       J 
    CSingleLock                      | 

    Puc. 2.1.    MFC 
    (     Microsoft Corporation) 


    2.  MFC  27 


       MFC 

         Windows   
-  MFC.     .   
    ,     .  
    Afx. ,      
"  AfxMessageBox().   4  ,     
    .       
,         
. (      
-.)  , Afx-    ,  
  . 

     AFXWIN.H 
     MFC-    AFXWIN.H.   (   
  )     MFC. 
      , 
  MFC,     WINDOWS.H.  ,   
   Windows-.     
API-    .   AFXWIN.H  
 ,         Windows-. 

     MFC- 

             MFC. 
   ,  MFC-    .   
    ,      
  ,   . 
       ,    MFC,  
 ,     : ,  
  ,  ,    .  
,        , 
  ,   ,   
 .    CWinApp,    CFrameWnd.   
 ,  ,   ,    
   . 
       ,      
  ,   Windows.   
    ,   ,   
    .    
    . 
      MFC-    : 
    1.     CFrameWnd  ,  . 
    2.     CWinApp  ,  . 

    28	MFC:   

    3.      . 
    4.      InitlnstanceQ  CWinApp. 
    5.      ,  . 
       ,   .    
 ,  ,  ,    
,   .  ,    
,    , ,   . 

    //  MFC- tinclude <afxwin.h> 
    //    
    //  ,      class CMainWin : 
public CFrameWnd      J { public: 
    CMainWin () ;	"2 
    DECLAREjyiESSAGE_MAP ()	-^ } 
    //      	/ijjjjjtfi CMainWin:: CMainWin ()        ^+^^'*^fa. 
    Create(NULL, "An MFC Application Skeleton"); 
    } 
    //  ,     class  : public CWinApp	0. 
    public: 
    BOOL Initlnstance (); } 
    //   
    BOOL ::Initlnstance ()	
    { 
    m_pMainWnd = new__CMainWin; 
    m_pMainWnd->ShowWindow (m_nCmdShow) ;  "WAfjhr  r^Jt* 
    m_pMainWnd->UpdateWindow();	f  
    return TRUE; } 
    //     BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd) 
   "2 END_MESSAGE_MAP()	"* 
     ; //    
    ,	_j 


    2.  MFC	29 

         . 2.2.   
  . 
     ,          
   ,   MFC.     ,  
   Windows       
.        ,  
     .   , 
     . 

     An MFC Application Skeleton 

    . 2.2. ,    

             
CFrameWnd.      CMainWin.    
:  CMainWin() _  DECLARE_MESSAGE_MAP().   
     CMainWin,    
 .   ,    , 
   .  ,     , 
  . (        
    ::.) 
         CMainWin    - 
Create().   ,  CFrameWnd    
CWnd, ,   ,   CCmdTarget,     CObject. 
 ,   ,   CFrameWnd,     
-  ,     .  
       ,      
      .    ,  , 

    30 MFC:   

    Create(),     .    
      CFrameWnd.     
   .       , 
   ,      . 
     ,    ,   
CWinApp.   ,      .  
   CWinThread, ,   ,   
CCmdTarget. CWinApp     -,   
 , InitlnstanccQ,   .   : 

    virtual BOOL CWinApp::Initlnstance(); 

    Initlnstance()    ,    
 ,    .      
 .  Initlnstance()   ,   
 .       
      . 
     Initlnstance()   .    
 CMainWin 1\_     m_pMainWnd.  
    CWinThread,    .  
  _CWnd*      MFC-,   
      .    
  -,    ,   
     . 
       ,  m_pMainWnd   , 
   CWnd.     ShowWindow().  
   : 

    BOOL CWnd::ShowWindow(int How); 

     ShowWindow() ,       
  .     How. , 
        m_nCmdShow. 
    CWinApp  ,     
   .       
    . ,     
How,   . 2.1. 

     2.1.   

     	 

    SW_HIDE	  
    SW_MAXIMIZE	     
    SW_MINIM1ZE	    
    SW_SHOW	  
    SW_RESTORE	     


    2.  MFC	31 

     ShowWindow()     .  
   ,   ,     
  . 
     ,   Initlnstance(),  UpdateWindow(). 
     CWnd. ,    ,  
        ,    
,         
Windows. ,   Windows     
  ,      . (  
    .) 
          : 

    BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd) END_MESSAGE_MAP() 

          .   
Windows    .      
  ,     . 
          ,    
  .     ,   , 
   Windows. 
                
,        ,     
 ,   CWinApp.    : 

      ; 

      ,         
CWinApp.        . 
       ,   ,    
.         
,    MFC-. 

       

      MFC-  Windows 3.1      
  .  ,      
,       Windows 95  Windows NT ( 
    32- ).     
  ,  ,   
,     "".    
  ,     . 
      ,       . 
     ,       
  ,   . ,    , 
      ,   
 . 

    DESCRIPTION 'Skeleton Program' EXETYPE WINDOWS 


    32	MFC:   


    CODE PRELOAD MOVEABLE DISCARDABLE DATA PRELOAD MOVABLE MULTIPLE HEAPSIZE 
8192 STACKSIZE 8192 

         DEF. ,   
  SKEL.DEF. 

         

           .  
      , ,  ,  
      .  ,  
      Create().   : 

BOOL CFrameWnd::Create(LPCSTR  ClassName,   //        
LPCSTR  Title,   //       
DWORD  Style=WS_OVERLAPPEDWINDOW,   //    
const  RECT   &XYsize=rectDefault,   //         CWnd   
*Parent=NULL,   //   - 
LPCSTR  MenuName=NULL,   //       
DWORD  FxStyle=0,   //        
CCreateContext   *Context=NULL,   //    
    //       ); 

     ,  ,   ,    
.           
Create(). ""  , ClassName,      
.     ''?"____,.   C++, 
 , , .     NULL ( ,  , 
 ),     ,    
MFC. , ,        
 AfxRegis-terWndClass().       
       ,   
      CreateQ. ,  
    ,   CFrameWnd,   
    . 
        ,     Title.  
    , ,  ,     . 
 ( )      Style. 
 \VS_OVER-LAPPEDWINDOW   ,    
 , ,  ,   .  
  ,   Style  .     
 ,       .  
         
.       . 2.2. 

    2.  MFC	33 


     2.2.    

     	  

    WS_OVERLAPPED	    
    WS_MAXIMIZEBOX	  
    WS MINIMIZEBOX	  
    WS_SYSMENU	  
    WS_HSCROLL	   
    WS_VSCROLL	   

           XYsize.  
   (  ),      Windows. 
   "1,"       
  RECT.  RECT   : 

    typedef struct tagRECT { 
    LONG left; 
    LONG top; 
    LONG right; 
    LONG bottom; } RECT; 

             
 left  top,         
right  bottom.   ,      
  (    ).  ,   
    .   ,     
    ,     
  .       
, , ,   Create()    . 
     Parent    ,   , 
  Create().        
   ,        
 NULL. 
          ,     
 .          
MenuName. (     .) 
          ExStyle.   
,  NULL. (      .) 
     , Context,   NULL.     
 CCreateContext.       
,   . 
     CreateQ   ,   ,  , 
   . 

    34	MFC:   

      ,           
Create(),     CMainWinQ  : 

    CMainWin::CMainWin() { 
    RECT   r; 
    .top  =   10;   .left  =   10; 
    .bottom = .right = 200; 
    Create (NULL, "A Small Window", 
    WSJDVERLAPPEDWINDOW, r); } 

          ,     
  (10,10),     (200,200).    . 2.3. 

    . 2.3.   


       CWinApp 

      Initlnstance()   mjnCmdShow  CWinApp 
   ,    : 
         ,     ,  
,    m_IpCmdLine. 
            ,    
 m_pszAppName. 
           ,    OnldleQ. 
  ,, &_    
 . 
        CWinApp     . 

    2.  MFC 35 


        

        ,  Windows-  . 
        .    
  MFC-     
,   ,   MFC.  
 ,      -  
     ,   -   
.    , , CLASSES.H     
 .        
 ,     ,   
 ,          . 
       ,       
.       ,   SKEL.H: 

    //      
    ,','       class CMainWin : public 
CFrameWnd { public: 
    CMainWin(); 
    DECLARE_MESSAGE_MAP() 
    }; 
    //      class CApp : public CWinApp { public: 
    BOOL Initlnstance (); }; 
      -        : 
    //  MFC- #include <afxwin.h> tinclude "skel.h" 
    //   CMainWin::CMainWin() { 
    Create(NULL, "An MFC Application Skeleton"); 
    //   BOOL CApp::Initlnstance () { 
    m_pMainWnd = new CMainWin; 


    36	MFC:   


    m_pMainWnd->ShowWindow(m_nCmdShow); m_pMainWnd->UpdateWindow(); 
    return TRUE; } 
    //           BEGIN_MESSAGE_MAP(CMainWin,   
CFrameWnd) END_MESSAGE_MAP() 
    CApp  App;   //         

     ,       AFXWIN.H,   
 SKEL.H.   ,    SKEL.H  
 ^^""""' 
          Windows  
,      .  ,   
. ,        
 . ,  ,   . 

    37