Hosting an ActiveX Control in WPF
来源:互联网 发布:社交网络 英语作文 编辑:程序博客网 时间:2024/06/04 19:04
http://msdn.microsoft.com/en-us/library/ms742735.aspx
- .NET Framework 3.5
- .NET Framework 3.0
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.
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.
To create and set up the project
Create a WPF Application project named HostingAxInWpf.
Add a Windows Forms Control Library project to the solution, and name the project WmpAxLib.
In the WmpAxLib project, add a reference to the Windows Media Player assembly, which is named wmp.dll.
Open the Toolbox.
Right-click in the Toolbox, and then click Choose Items.
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.
In Solution Explorer, right-click the UserControl1 file, and then click Rename.
Change the name to WmpAxControl.vb or WmpAxControl.cs, depending on the language.
If you are prompted to rename all references, click Yes.
Microsoft Visual Studio automatically generates an AxHost 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
Open WmpAxControl.vb or WmpAxControl.cs in the Windows Forms Designer.
From the Toolbox, add the Windows Media Player control to the design surface.
In the Properties window, set the value of the Windows Media Player control's Dock property to Fill.
Build the WmpAxLib control library project.
To host the ActiveX control
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.
Add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll.
Add a reference to the Windows Forms assembly, which is named System.Windows.Forms.dll.
Open MainWindow.xaml in the WPF Designer.
Name the Grid element grid1.
XAMLCopy<Grid Name="grid1">
</Grid>In Design view or XAML view, select the Window element.
In the Properties window, click the Events tab.
Double-click the Loaded event.
Insert the following code to handle the Loaded event.
This code creates an instance of the WindowsFormsHost control and adds an instance of the AxWindowsMediaPlayer control as its child.
VBC#C++F#JScriptCopyprivate 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";
}Press F5 to build and run the application.
Reference
Concepts
Other Resources
Date
History
Reason
August 2010
Updated for Visual Studio 2010.
Customer feedback.
- Hosting an ActiveX Control in WPF
- Hosting ActiveX in Win32
- Hosting a Win32 Control in WPF 在wpf中使用win32 控件
- Visual C++ ActiveX Control for hosting Office documents in Visual Basic or HTML
- Creating an ActiveX Control in Visual Studio 2005
- Reloading an ActiveX control error
- Hosting Office in a WPF Application
- Walkthrough: Hosting Direct3D9 Content in WPF
- Printf() debugging in a console window from within an ActiveX control
- Adding ActiveX Control OCX to WPF
- Dialog frame as an ActiveX control(收藏)
- Dialog frame as an ActiveX control.
- How to add an ActiveX Control
- WebBrowser control Hosting Office documents in .NET forms
- Hosting a Windows Control in a Web Form
- How to start a second thread in an MFC-based ActiveX control to fire events in Visual C++
- Walkthrough: Creating Direct3D9 Content for Hosting in WPF
- Using VS2010 Develop ActiveX Control in Windows Form Control Libarary
- Java的Scan
- 清除www.2345.com修改首页的方法
- 线程中CreateEvent和SetEvent及WaitForSingleObj
- 清理桌面不能删除不掉的Internet图标
- 在网上无意中发现的好东东啊 一起分享一下
- Hosting an ActiveX Control in WPF
- free与new的实现
- LINQ方式查询数据库
- MFC和Flash的完整通讯
- HTML5 - 多媒体
- poj 1002 487-3279
- Winsock编程——WSAAsyncSelect模型
- 2010.9.14 华为面试心得
- national