My MFC hasn't used it, although now Java, C # waiting for the language, Java, .NET platform is also gradually replacing the Win32 platform, but I think that MFC is also worth learning, um, look at the face of the market Let's go to work tomorrow, you have to find a job, :),
Learn Win32 API C has been in nearly 2 years, Delphi is also 2 months, and the old birds who have been programmed for 10 years, I may not even have a small bird, there is no experience in any VC project (Delphi's The project has been done). But the newly born calf is not afraid of tiger, but now the social people is open, and the freedom of speech in the network, I also want to speech free. No one dares to say that VC is not, but mentioning MFC, mostly said garbage, MFC is garbage, it is best to have a truth:
Well, starting from Delphi's TForm, in the MFC, similar to TForm is CView, CDialog, first look at CView: Class CView: Public CWnd {declare_dynamic (cView) // Constructorsprotace: CView (); // attributesspublic: CDocument * GetDocument () const; // Operationspublic: // for standard printing setup (override OnPreparePrinting) BOOL DoPreparePrinting (CPrintInfo * pInfo); // Overridablespublic: virtual BOOL IsSelected (const CObject * pDocItem) const; // support for OLE / / OLE scrolling support (used for drag / drop as well) virtual BOOL OnScroll (UINT nScrollCode, UINT nPos, BOOL bDoScroll = TRUE); virtual BOOL OnScrollBy (CSize sizeScroll, BOOL bDoScroll = TRUE); // OLE drag / drop supportvirtual DROPEFFECT OnDragEnter (COleDataObject * pDataObject, DWORD dwKeyState, CPoint point); virtual DROPEFFECT OnDragOver (COleDataObject * pDataObject, DWORD dwKeyState, CPoint point); virtual void OnDragLeave (); virtual BOOL OnDrop (COleDataObject * pDataObject, DROPEFFECT dropEffect, CPoint point); virtual DROPEFFECT OnDROPEX (COleDataObject * pDataObject, DROPEFFECT dropDefault, DROPEFFECT dropList, CPoint point); virtual DROPEFFECT OnDragScroll (DWORD dwKeyState, CPoint point); virtual void OnPrepareDC (CDC * pDC, CPrintInfo * pInfo = NULL); virtual void OnInitialUpdate (); // called first time after constructprotected: // Activationvirtual void OnActivateView (BOOL bActivate, CView * pActivateView, CView * pDeactiveView); virtual void OnActivateFrame (UINT nState, CFrameWnd * pFrameWnd); // General drawing / updatingvirtual void OnUpdate (CView * pSender, LPARAM lHint , Cobject * phint; Virtual Void OnDraw (CDC * PDC) = 0; // Printing SupportVirtual Bool Onprepareprinting (CPrintInfo * Pinfo);
// must override to enable printing and print previewvirtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo); virtual void OnPrint (CDC * pDC, CPrintInfo * pInfo); virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo); // Advanced: end print preview mode, move to pointvirtual void OnEndPrintPreview (CDC * pDC, CPrintInfo * pInfo, POINT point, CPreviewView * pView); // Implementationpublic: virtual ~ CView (); # ifdef _DEBUGvirtual void Dump (CDumpContext &) const; virtual void AssertValid () const; #endif // _ DEBUG // Advanced: for implementing custom print previewBOOL DoPrintPreview (UINT nIDResource, CView * pPrintView, CRuntimeClass * pPreviewViewClass, CPrintPreviewState * pState); virtual void CalcWindowRect (LPRECT lpClientRect, UINT nAdjustType = adjustBorder) ; virtual CScrollBar * GetScrollBarCtrl (int nBar) const; static CSplitterWnd * PASCAL GetParentSplitter (const CWnd * pWnd, BOOL bAnyState); protected: CDocument * m_pDocument; public: virtual BOOL OnCmdMsg (UINT nID, int nCode, void * pExtra, AFX_CMDHANDLERINFO *pHandlerInfo); protected: virtual BOOL PreCreateWindow (CREATESTRUCT & cs); virtual void PostNcDestroy (); // friend classes that call protected CView overridablesfriend class CDocument; friend class CDocTemplate; friend class CPreviewView; friend class CFrameWnd; friend class CMDIFrameWnd; friend class CMDIChildWnd ; friend class CSplitterWnd; friend class COleServerDoc; friend class CDocObjectServer; // {{aFX_MSG (CView) afx_msg int OnCreate (LPCREATESTRUCT lpcs); afx_msg void OnDestroy (); afx_msg void OnPaint (); afx_msg int OnMouseActivate (CWnd * pDesktopWnd, UINT NHITTEST, UINT Message; // Commandsafx_msg Void OnUpdateSplitcmd (ccmdui * PCMDUI); AFX_MSG Bool OnSplitcmd (Uint Nid); AFX_MSG Void OnupDateNextPaneMenu (ccmdui * pcmdui);
afx_msg BOOL OnNextPaneCmd (UINT nID); // not mapped commands - must be mapped in derived classafx_msg void OnFilePrint (); afx_msg void OnFilePrintPreview (); //}} AFX_MSGDECLARE_MESSAGE_MAP ()}; 0: Comments Code Explanation
protected: cview (); // Indicates that CView can only be used to inherit, and cannot be instantiated
Bool doprepareprinting (CPrintInfo * Pinfo); // To get the printing effect, you must override this function, set the printer
Virtual void onpreparedc (CDC * PDC, CPrintInfo * PINFO = NULL);
/ / From this function, set the printer effect must be Override that function This function and how the doprepareprinting () function cooperates?
Bool doprepareprinting (CPrintInfo * Pinfo); // To get the printing effect, you must override this function, set the printer
1: Since there is a virtual void onDraw (CDC * PDC) = 0, the virtual function, indicating that the class is an abstract class, the CONSTRUctor of the class is not necessary for protected, and the publication can also meet the requirements, but using protected more strictly follows the language of C language. .
2: Friends of CVIEW:
friend class CDocument; friend class CDocTemplate; friend class CPreviewView; friend class CFrameWnd; friend class CMDIFrameWnd; friend class CMDIChildWnd; friend class CSplitterWnd; friend class COleServerDoc; friend class CDocObjectServer;
CVIEW's Friends Class is the MVC architecture, document class, cdocument, causerverdoc, cdocobjectserver, framework class: CDOCTemplate, CFrameWnd, CMDIFrameWnd, Controller, CmIDFrameWnd, CmdichildWnd, View Class: CpreviewView
3: CVIEW class accepted message
// {{AFX_MSG (CView) afx_msg int OnCreate (LPCREATESTRUCT lpcs); afx_msg void OnDestroy (); afx_msg void OnPaint (); afx_msg int OnMouseActivate (CWnd * pDesktopWnd, UINT nHitTest, UINT message); // commandsafx_msg void OnUpdateSplitCmd (CCmdUI * pCmdUI); afx_msg BOOL OnSplitCmd (UINT nID); afx_msg void OnUpdateNextPaneMenu (CCmdUI * pCmdUI); afx_msg BOOL OnNextPaneCmd (UINT nID); // not mapped commands - must be mapped in derived classafx_msg void OnFilePrint (); afx_msg void OnFilePrintPreview ( ); //}} AFX_MSGDECLARE_MESSAGE_MAP ()
The partial function can be equivalent to the Delphi event function, onCreate (), from the name, is just created, used to set the shape, characteristics, etc. of the View, quite with TFORM's Procedure TFORM1.FormCreate (Sender: TOBJECT); Formcreate () event, and ONDSTROY () is equal to: procedure tform1.formDestroy (sender: TOBJECT); Since the MFC message processing function is directly with the Win32 message, it can be seen that the CView class is a function of processing messages. Extremely lack. And Delphi's TFORM is extremely rich. In fact, the TForm class corresponds to the CDialog, just the MFC does not intend to use CDIALOG as a container of other control classes, so it is designed to handle other more messages. The following will discuss this problem!
{TForm} TForm = class (TCustomForm) public ... property OnActivate; property OnCanResize; property OnClick; property OnClose; property OnCloseQuery; property OnConstrainedResize; property OnContextPopup; property OnCreate; property OnDblClick; property OnDestroy; property OnDeactivate; property OnDockDrop; property OnDockOver; property OnDragDrop; property OnDragOver; property OnEndDock; property OnGetSiteInfo; property OnHide; property OnHelp; property OnKeyDown; property OnKeyPress; property OnKeyUp; property OnMouseDown; property OnMouseMove; property OnMouseUp; property OnMouseWheel; property OnMouseWheelDown; property OnMouseWheelUp; property OnPaint; Property OnResize; Property OnShortcut; Property OnStartDock; Property Onundock; End;
Of course, in addition to a few, other messages are the news of VCL themselves! 4: Funny onDraw and onpaint
Virtual void OnDraw (CDC * PDC) = 0;
AFX_MSG void onpaint ();
From the function declaration, it seems that OnDraw is a general function, but OnPaint is a WM_PAINT message function, but if OnPaint is not ONPAINT, OnPaint calls ONDRAW to process the message. This method is a bit close to Delphi practice. Can't be one-on-one, otherwise, I also use MFC to dry, I use the Win32 API directly.
/ void CEX03AVIEW :: OnDraw (CDC * PDC) {PDC-> Textout (300, 500, "Hello Cex03aview :: OnDraw (CDC * PDC) Function");} Void Cex03Aview :: OnPaint () {CPAINTDC DC (this) ; // device context for paintingdc.textout (300, 400, "Hello Cex03aview :: OnPaint Function");}
ONPAINT is after Override, OnDraw loses the effect. The above code is displayed as "Hello CEX03AVIEW :: OnPaint Function"
5: Delphi's PME structure (attribute event) and VC (M) FC structure (basic class), advanced generation, now Java and C # also provide PME structure, is this coincidence? Of course, Java's JavaBean is SUN delegated Borland, C # and .NET designer Anders is the founder of Delphi. So Java SDK and C # language, .NET FrameWord and Delphi language, VCL library God, is not surprising. So far, there is no news that Microsoft wants to go out of MFC.net, I think it is impossible, which is not only a market reason, but the design of MFC is too late. The launch of Delphi8, the vcl.Net is born, and then the good design of VCL has always been leading the world trend of FrameWord.
6: The MFC is extremely backward, which is extremely ugly, which is a failure product from the technology. But why is it successful? This says the biggest advantage of MFC: flexible, efficient, simple.
Flexible: This is due to the C / C language. I don't have to say more.
Efficient: Or thanked C / C language. The characteristics of C / C language, flexible and efficient, I believe everyone will not forget.
Simple: Everyone compares the MFC and VCL, will believe that VCL is indeed more than MFC, the high-level skills in VCL, and there are even many compilation in the VCL program code. This is all expectant. And the MFC, simple packaging, simple use, although it lost RAD, but this is also the reason why everyone likes.
The success of the MFC is a large extent, but the Japanese failure of the C / C , VCL is successful in Delphi's elegant, powerful, patented OO language
Oh, MFC, when the empire is falling, or put it in the history of history!
Of course, you can't rely on something that is not as different, it is called "great" FrameWord --- MFC, otherwise it will make people feel faint, so there will be a series of learning experience ...
To Be Continued
--- 2004-7-2 by LitTleroy