Win32 MFC.cpp:Defines The entry point for the application.
//
#include "stdafx.h"
Class Cmyframewnd:public CFrameWnd
{
Adding a declaration macro within a class
Declare_message_map ()
Public://Declaration of message functions within the standard implementation class
afx_msg int OnCreate (LPCREATESTRUCT CS);
afx_msg void OnPaint ();
/* Non-standard implementation in-class declaration of message functions
Declaring message functions within a class
Public
LRESULT OnCreate (WPARAM wparam,lparam LPARAM);
LRESULT OnPaint (WPARAM wparam,lparam LPARAM);
*/
};
Out-of-class
Begin_message_map (Cmyframewnd,cframewnd)//(This class and base class)
Add a message between Begin and end
On_wm_create ()
On_wm_paint ()
End_message_map ()
Standard form to implement the definition of the message function outside the class
int Cmyframewnd::oncreate (LPCREATESTRUCT cs)
{
AfxMessageBox ("A window is about to be created! ");
return 0;
}
void Cmyframewnd::onpaint ()
{
Paintstruct ps={0};
HDC Hdc=::beginpaint (THIS->M_HWND,&PS);
:: TextOut (hdc,200,200, "Hello", 5);
:: EndPaint (M_HWND,&PS);
}
/* Definition of non-standard implementation out-of-class functions
Implementing window creation functions outside of the class
LRESULT cmyframewnd::oncreate (WPARAM wparam,lparam LPARAM)
{
AfxMessageBox ("A window is about to be created! ");
return 0;
}
Out-of-class implementation of drawing capabilities
LRESULT cmyframewnd::onpaint (WPARAM wparam,lparam LPARAM)
{
Paintstruct cs={0};
HDC Hdc=::beginpaint (THIS->M_HWND,&CS);
:: TextOut (hdc,200,200, "Hello", 5);
:: EndPaint (M_HWND,&CS);
return 0;
}
*/
Application Classes
Class Cmywinapp:public CWINAPP
{
Public
CMyWinApp ();
Virtual BOOL InitInstance ();
};
CMyWinApp Theapp;
Cmywinapp::cmywinapp ()
{
}
Re-add virtual function function
BOOL cmywinapp::initinstance ()
{
Cmyframewnd *pframe=new Cmyframewnd ();
Pframe->create (NULL, "mfccmd");
M_pmainwnd=pframe;
Pframe->showwindow (Sw_show);
Pframe->updatewindow ();
return TRUE;
}
Implementation of MFC window creation in WIN32 application environment