博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Hosting an ActiveX Control in WPF
阅读量:4031 次
发布时间:2019-05-24

本文共 3891 字,大约阅读时间需要 12 分钟。

http://msdn.microsoft.com/en-us/library/ms742735.aspx

 

 

Walkthrough: Hosting an ActiveX Control in WPF
.NET Framework 4

Updated: August 2010

To enable improved interaction with browsers, you can use Microsoft ActiveX controls in your WPF-based application. This walkthrough demonstrates how you can host the Microsoft Windows Media Player as a control on a WPF page.

Tasks illustrated in this walkthrough include:

  • Creating the project.

  • Creating the ActiveX control.

  • Hosting the ActiveX control on a WPF Page.

When you have completed this walkthrough, you will understand how to use Microsoft ActiveX controls in your WPF-based application.

Prerequisites

You need the following components to complete this walkthrough:

  • Microsoft Windows Media Player installed on the computer where Visual Studio is installed.

  • Visual Studio 2010.

Creating the Project

To create and set up the project

  1. Create a WPF Application project named HostingAxInWpf .

  2. Add a Windows Forms Control Library project to the solution, and name the project WmpAxLib .

  3. In the WmpAxLib project, add a reference to the Windows Media Player assembly, which is named wmp.dll.

  4. Open the Toolbox .

  5. Right-click in the Toolbox , and then click Choose Items .

  6. Click the COM Components tab, select the Windows Media Player control, and then click OK .

    The Windows Media Player control is added to the Toolbox .

  7. In Solution Explorer, right-click the UserControl1 file, and then click Rename .

  8. Change the name to WmpAxControl.vb or WmpAxControl.cs , depending on the language.

  9. If you are prompted to rename all references, click Yes .

Creating the ActiveX Control

Microsoft Visual Studio automatically generates an wrapper class for a Microsoft ActiveX control when the control is added to a design surface. The following procedure creates a managed assembly named AxInterop.WMPLib.dll.

To create the ActiveX control

  1. Open WmpAxControl.vb or WmpAxControl.cs in the Windows Forms Designer.

  2. From the Toolbox , add the Windows Media Player control to the design surface.

  3. In the Properties window, set the value of the Windows Media Player control's property to .

  4. Build the WmpAxLib control library project.

Hosting the ActiveX Control on a WPF Page

To host the ActiveX control

  1. In the HostingAxInWpf project, add a reference to the generated ActiveX interoperability assembly.

    This assembly is named AxInterop.WMPLib.dll and was added to the Debug folder of the WmpAxLib project when you imported the Windows Media Player control.

  2. Add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll.

  3. Add a reference to the Windows Forms assembly, which is named System.Windows.Forms.dll.

  4. Open MainWindow.xaml in the WPF Designer.

  5. Name the element grid1 .

  6. In Design view or XAML view, select the element.

  7. In the Properties window, click the Events tab.

  8. Double-click the event.

  9. Insert the following code to handle the event.

    This code creates an instance of the control and adds an instance of the AxWindowsMediaPlayer control as its child.

    private void Window_Loaded(object sender, RoutedEventArgs e) {
    // Create the interop host control. System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost(); // Create the ActiveX control. AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer(); // Assign the ActiveX control as the host control's child. host.Child = axWmp; // Add the interop host control to the Grid // control's collection of child controls. this.grid1.Children.Add(host); // Play a .wav file with the ActiveX control. axWmp.URL = @"C:/Windows/Media/tada.wav"; }
  10. Press F5 to build and run the application.

See Also

Reference

Concepts

Other Resources

Change History

Date

History

Reason

August 2010

Updated for Visual Studio 2010.

Customer feedback.

转载地址:http://maqbi.baihongyu.com/

你可能感兴趣的文章
ReactNative使用Redux例子
查看>>
Promise的基本使用
查看>>
android给文字加边框(修改不能居中的问题)
查看>>
coursesa课程 Python 3 programming 统计文件有多少单词
查看>>
coursesa课程 Python 3 programming 输出每一行句子的第三个单词
查看>>
coursesa课程 Python 3 programming Dictionary methods 字典的方法
查看>>
Returning a value from a function
查看>>
coursesa课程 Python 3 programming Functions can call other functions 函数调用另一个函数
查看>>
coursesa课程 Python 3 programming The while Statement
查看>>
course_2_assessment_6
查看>>
coursesa课程 Python 3 programming course_2_assessment_7 多参数函数练习题
查看>>
coursesa课程 Python 3 programming course_2_assessment_8 sorted练习题
查看>>
visca接口转RS-232C接口线序
查看>>
在unity中建立最小的shader(Minimal Shader)
查看>>
1.3 Debugging of Shaders (调试着色器)
查看>>
关于phpcms中模块_tag.class.php中的pc_tag()方法的含义
查看>>
vsftp 配置具有匿名登录也有系统用户登录,系统用户有管理权限,匿名只有下载权限。
查看>>
linux安装usb wifi接收器
查看>>
终于搞定CString和string之间转换的问题了
查看>>
用防火墙自动拦截攻击IP
查看>>