Implementation of MFC window creation in WIN32 application environment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.