DIRECTX8 under the MFC architecture

Source: Internet
Author: User
Tags bool

Chapter I. MFC framework

(DX8MFC)

The MFC framework here refers to a game development application framework, of course, you can also write a meeting with your requirements of the MFC framework. If you are familiar with MFC, you can start reading from the second chapter directly. This framework is the basis for a few examples, if you do not know MFC very well, you should read this chapter carefully, in order to have an in-depth understanding of this MFC framework.

The framework includes two classes:

Cdx8mfcapp classes and Cframewin classes, Cdx8mfcapp classes are application classes, Cframewin classes are the main classes of the framework, and most of our code is expanded from here. First look at the Cdx8mfcapp class, which includes member functions such as Cdx8mfcapp (), ExitInstance (), InitInstance (), OnIdle (LONG lcount), and a game object.

The InitInstance () member function is invoked when the program is initialized, where I set up a window:

BOOL CDX8MFCApp::InitInstance()
{
// The one and only window has been initialized, so show and update it.
m_pMainWnd = new CFrameWin();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
Game = (CFrameWin*) m_pMainWnd;
Game->Init();
return TRUE;
}

The ExitInstance () member function is called when the program terminates, where we release some objects and pointers:

int CDX8MFCApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call the base class
Game->End();
delete Game;
return CWinApp::ExitInstance();
}

The OnIdle (LONG lcount) member function is invoked when there is no Windows message to process, meaning that the OnIdle () member function is called continuously, which is exactly what we use as a game loop.

BOOL CDX8MFCApp::OnIdle(LONG lCount)
{
// TODO: Add your specialized code here and/or call the base class
if(Game->window_active==TRUE)
{
Game->Active();
Game->window_active=FALSE;
}
Game->Go();
return TRUE;
}

The game object is a Cframewin class pointer, and we create a Cframewin object in the InitInstance () member function and assign the pointer value of the Cframewin object to game.

Now let's take a look at the Cframewin class, which includes member functions such as active (), end (), go (), Init (), Update ().

Init () member function, where you can do some initialization of your own. Recalling the InitInstance () member function of the Cdx8mfcapp class, The Game->init () is called in the InitInstance () member function after the completion window is initialized, meaning that Init () is invoked after the window is initialized.

void CFrameWin::Init()
{
AfxMessageBox("Init");
}

The Go () member function is called repeatedly, and it calls update () and DestroyWindow (). Update () is used for updating Windows, and calling DestroyWindow () ends the application. If you delete the DestroyWindow () statement, the program will continue to loop.

void CFrameWin::Go() //Game循环
{
AfxMessageBox("Go");
Update();
DestroyWindow();
}
Active()成员函数会在应用程序被击活的时候被调用。
void CFrameWin::Active() //窗口被激活
{
TRACE("Active\n");
AfxMessageBox("Active");
}

This program doesn't do anything, just an MFC framework. You can download the source program from the http://gamedev.363.net, or obtain it from the author by E-mail:laical@21cn.com.

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.