Use an example to learn MFC

xiaoxiao2021-03-06  49

example

It is best to understand the structure and style of a typical MFC program to enter a small program, then compile and run it. The following program is a simple "Hello World" program. This is very familiar with many C programmers, let's take a look at how to use the MFC method. If you see such a program for the first time, it may be more difficult to understand. This doesn't matter, we will introduce it in detail later. Now you can build, compile and run it in the Visual C environment.

//Hello.cpp

#include

// Describe the application class

Class ChelloApp: Public CWINAPP

{

PUBLIC:

Virtual Bool InitInstance ();

}

// Establish an instance of the application class

ChelloApp HelloApp;

/ / Describe the main window class

Class Chellowindow: Public CFrameWnd

{

CSTATIC * CS;

PUBLIC:

CHELLOWINDOW ();

}

/ / Whenever the application is called for the first time execution, the initialization function is called

Bool chelloApp :: InitInstance ()

{

m_pmainwnd = new chellowindow ();

m_pmainwnd-> showwindow (m_ncmdshow);

m_pmainwnd-> UpdateWindow ();

Return True;

}

// Window constructor

Chellowindow :: chellowindow ()

{

// Create the window itself

Create (NULL,

"Hello World!",

WS_OVERLAPPEDWINDOW,

CRECT (0,0,200,200));

// Establish a static label

CS = new cstatic ();

CS-> CREATE ("Hello World",

WS_CHILD | WS_VISIBLE | SS_CENTER,

CRECT (50, 80, 150, 150),

THIS);

}

转载请注明原文地址:https://www.9cbs.com/read-60241.html

New Post(0)