Playing flash with the MFC ActiveX Control

Source: Internet
Author: User

I believe that many people have done this thing. I am a newbie in this regard. The first time I did this, I had a bad breath.

In fact, there is a difficulty in calling ActiveX controls in ActiveX controls. another difficulty is that the online example is basically implemented in VC 6.0. The ide I use is vs2005. To be honest, I didn't know how to add the oncreate method at the beginning. I cannot use vc6.0. however, vs2005 can debug breakpoints, but vc6.0 won't. This is much better.

 

The first question is to call the acticex control http://www.bafee.cn/JC/Prog2/VC_/1839_20081101015125F1006.HTML In the MFC controls to find the answer.

 

Second problem solution: In "Class View" right-click ** CTRL class, select "attribute", http://hi.csdn.net/attachment/201005/21/1082190_1274438958rD6B.jpg picture (this editor, I am speechless, insert picture JS error, IE6)

 

Let's get started with our project.

 

Step 1

 

Create an MFC ActiveX control project named "abcocx". You can use other options by default.

 

Step 2

 

After the project is created, the program automatically contains three classes and one library.

  • Cabcocxapp and Application
  • Cabcocxctrl class, control window class, oncreate and ondraw method execution class
  • Abcocxlib, which has two interfaces: _ dabcocx and _ dabcocxevents, including control attributes and Methods

Step 3

 

I used the cshockwaveflash control to play flash, so I want to add it.

Click "project"-> "add class"-> "MFC class in ActiveX Control". The dialog box is displayed.

Http://hi.csdn.net/attachment/201005/21/1082190_12744409870Zoa.jpg

Select "Shockwave Flash Object", as shown in the figure.

 

In this way, an additional class is added.

  • Cshockwaveflash and flash Control

Step 4

 

Add the cshockwaveflash variable m_flash in "cabcocxctrl. H" (manually added)

 

Specifically, add # include "cshockwaveflash. H"

Cshockwaveflash m_flash; // or cshockwaveflash * m_flash; write m_flash = new cshockwaveflash () in the oncreaete method ();

 

Step 5 (required)

The most important part is to check cabcocxapp. whether afxenablecontrolcontainer () exists in the initinstance () Definition of CPP. If this code is not provided, add this code. Otherwise, when you pass the actual parameter this to the m_flash.create method, memory will conflict (I think it is a null pointer problem ).

 

Step 6 (required)

 

Add "wm_create" information to the cabcocxctrl class. "Class View" right-click the cabcocxctrl class, select "properties", and click "information" in the "properties" window. You should know the following operations.

 

Generate afx_msg int oncreate (maid) method,

Add code

M_flash.create (L "Flash", ws_child | ws_visible | ws_hscroll | ws_vscroll, crect (500,500, 102), this,); // This Code does not work in other methods.

 

The parameter is not much said, but if there is no step 5, an error is reported here. The reason is this. You can add a breakpoint in this Code and debug it on your own.

 

Step 7

 

Add the code in the definition of the cabcocxctrl class oncreate () method:

 

M_flash.loadmovie (0, l "G:/logo.swf"); // flash 10d. ocx no setmovie Method
M_flash.play ();

 

 

Step 8

 

Start debugging, select "ActiveX control test container", right-click the blank area in the middle, and choose "Insert new control" from the right-click menu. Haha, I know the benefits of my project name, check "abcocx control" and double-click it to open a box. This is the window of our "abcocx" ActiveX control.

 

Of course, you can also choose to test in IE, but the premise is that you have to write the HTML page added to this ActiveX object.

 

 

This is the simplest example, and I will not -.-!!

This must be noted in step 5 and step 6, afxenablecontrolcontainer (); and in the oncreate () method, execute the m_flash.create () method, m_flash.create () method execution in other methods does not work. In front of me, it is executed in the constructor cabcocxctrl (). The flash will not be played, my God!

 

The callfunction () method of cshockwaveflash is the interface for the interaction between the main VC code and the flash file's ActionScript. Unfortunately, this method cannot be executed in IE browser (pure IE browser, which is not included in IE kernel. this issue is not officially answered!

 

 

 

 

 

 

 

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.