Development of DirectX games based on ActiveX Controls

Source: Internet
Author: User

The development of DirectX games is usually based on sdks or MFC. Everyone must have a lot of knowledge about the development of the two. However, the development of DirectX games based on ActiveX controls is rare on the Internet, I am interested in studying it recently. I have little achievements and do not dare to enjoy it exclusively. I hope I can use it as an example.

I chose WIN2K + VC6 + DirectX8 as the development platform. First, I created the MFC ActiveX ControlWizard. Assume that the project name is DIG (this name is used when I create a game named Digger ). The compilation of ActiveX controls requires that resources must be completely released, or it will give you a variety of troubles. The error prompt box will prompt you to feel the world is dark, therefore, you must pay attention to resource management. In fact, C ++ requires programmers to manage resources in this province.

After completing these steps, I encountered a difficulty in initializing DirectX and could not obtain the HWND. Without this, how can I initialize the D3D device? I searched various classes for a long time, finally, this handle is found in the secret. In the OnDraw function, the CDC * pdc can indirectly obtain this handle. pdc-> GetWindow ()-> m_hWnd (# add is not good, dlg directly has m_hWnd members ).

After obtaining the handle, initialize the DirectX device. Here I chose ID3DXSprite as the graphic display interface. It is powerful and easy to operate and supports scaling, translucent, and rotating. Because MFC encapsulates Windows messages, you cannot simply use the SDK Message Processing Program (that is, there is a message processing message, no message rendering graphics ). If the rendering function is directly executed in the OnDraw function, after compilation, you can test ActiveX Control Text iner to find that the entire program is running, but the ActiveX size cannot be adjusted, and ActiveX
All the operations of Control Text Container are extremely lagging behind, so the developed ActiveX Control is meaningless. Therefore, it is a good choice to open a separate thread for the function that executes rendering, the CreateThread function is used to create a thread. It turns out that the FPS obtained by this method is still objective and completely satisfied with the direct insertion of ActiveX controls on the webpage for the game, it is also easy to test the effect on the web page. Open the FrontPage and insert the ActiveX control. It is completely compatible without a piece of code. Imagine if this is very exciting, theoretically speaking, the vast majority of DirectX-based games can be made into ActiveX controls, other I did not test, you can test their own, there are new discoveries don't forget to tell me gogoplayer@163.com, the following are the source code for reference only.

 

HINSTANCE g_hInst; // instance

HWND g_hWnd; // handle

CSSInput g_threadInput; // enter the device

 

HANDLE g_hThread;

DWORD g_dwThreadID;

Bool g_bIsRunning;

Bool g_bIsInitialise;

 

CDIGCtrl: CDIGCtrl ()

{

InitializeIIDs (& IID_DDIG, & IID_DDIGEvents );

 

G_bIsInitialise = false;

 

// TODO: Initialize your control's instance data here.

}

 

//////////////////////////////////////// /////////////////////////////////////

// CDIGCtrl ::~ CDIGCtrl-Destructor

 

CDIGCtrl ::~ CDIGCtrl ()

{

// TODO: Cleanup your control's instance data here.

// Release

GameRelease ();

}

 

 

//////////////////////////////////////// /////////////////////////////////////

// CDIGCtrl: OnDraw-Drawing function

 

// Rendering thread

Void WINAPI ListenThread (void)

{

G_bIsRunning = true;

While (g_bIsRunning = true)

{

G_threadInput.Capture ();

If (g_threadInput.IsUp (DIK_ESCAPE ))

G_bIsRunning = false;

Render ();

}

Return;

}

 

Void CDIGCtrl: OnDraw (

CDC * pdc, const CRect & rcBounds, const CRect & rcInvalid)

{

If (g_bIsInitialise = false)

{

G_hInst = AfxGetInstanceHandle ();

G_hWnd = pdc-> GetWindow ()-> m_hWnd;

InitGame ();

G_threadInput.Create (g_hInst, g_hWnd );

G_bIsInitialise = true;

G_hThread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ListenThread, (void *) this, 0, & g_dwThreadID );

}

}

 

At the end of the article, I also tested the ActiveX control with VB, which worked very well. It felt great to implement the game with a single stroke, a form, a control, and 0 lines of code.

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.