About Using ActiveX Components in later versions of the vc6 MFC Program

Source: Internet
Author: User

After watching the second round of Rockets play at home and Lakers in the playoffs, I lost again in expectation. Although I always hope that the rockets will become a dark horse and create a miracle.

There is no need to open csdn. We can see that there is a TX question about how to use the WMP control in the MFC program under vs2003. What do we say about vs2003 2005 and the previous

Vc6 is not the same, so I tried it and found that there were some changes.

Under vc6, insert an ActiveX component directly in the MFC project, and create a member of the control type for it. At the same time, MFC will generate many related packaging classes for this component, for example, WMP generates cwmpplayer4 cwmpcontrol cwmpsettings and so on (you can determine whether to generate the corresponding packaging class ). Then you can use these classes to control wmplayer operations.

What about vs2003? Follow the steps above to create an MFC dialog box, insert a wmplayer control in it, and then add a member variable to it, the wizard automatically generates an ocx1 window derived class (cwnd) member. How can I use this ocx1? I didn't directly package all interfaces of the WMP control. Do I still need to use native interfaces or idispatch interfaces?

Later I found out how to generate the wraper class in vs2003 and later versions.

Select a project, right-click and select "add class", select "generate MFC class from ActiveX control", and then select our control (from the current control list of the system and the registered Control List ). Here we select the "Windows Media Player" control. Some WMP interfaces will be listed on the left after selection. Select the interfaces on the left and add them to the right, the wizard generates the corresponding packaging class for this interface. At this point, we should find that vc6 is actually the same. For example, here we select the iwmpplayer interface, and the wizard will wrap it as cwmpplayer4 class. Then we can add a control member for the WMP control in the dialog box and set its type to cwmpplayer4, then you can use the following code to control the playback:

Cwmpplayer4 m_player; // member variables defined in the DLG header file

 

// Play the file

Cwmpsettings2 set = m_player.get_settings ();
Set. put_autostart (false );
M_player.put_url (_ T ("E: // testproject // media // Kunming Lake "));

// Control pause and Playback

Cwmpcontrols3 control = m_player.get_controls ();
If (m_bpause = true)
{
Control. Play ();
}
Else
{
Control. Pause ();
}

M_bpause =! M_bpause;

 

Wait ......

 

Note one problem: when ActiveX is used to create an MFC class, the test shows that the first one is derived from cwnd, the latter is derived from the coledispatchdriver. However, this is not necessarily the case. I first added cwmpplayer4 cwmpcontrols2 and then added cwmpsettings. I found that cwmpsettings are derived from cwnd, but it doesn't matter. I directly changed its base class to coledispatchdriver, modify the constructor slightly. Note that the member variables of the WMP control DDX of the dialog box must be of the type derived from cwnd. For example, the cwmpplayer4 I added is derived from cwnd, so the DDX ing is as follows:

Ddx_control (PDX, idc_ocx1, m_player );

 

 

Finally, the problem of the generated wrapper base class is a bug in IDE. Someone has suggested that it should be solved in orcas beta2. I look forward to it...

Http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx? Feedbackid = 291427

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.