简体   繁体   English

C#ActiveX / IE 10 /多个选项卡/获取ActiveX MainWindowHandle

[英]C# ActiveX / IE 10 / Multiple Tabs / Get ActiveX MainWindowHandle

I have an ActiveX project running happily in IE10. 我有一个在IE10中愉快运行的ActiveX项目。

A situation has occured that requires me to obtain the MainWindowHandle of the tab the control is running in. 发生了一种情况,要求我获取正在运行控件的选项卡的MainWindowHandle。

The following code returns the MainWindowHandle for IE - and not the tab the ActiveX control is running in: 以下代码返回IE的MainWindowHandle-而不是运行ActiveX控件的选项卡:

 Process.GetCurrentProcess().MainWindowHandle

If I run this code it returns more than one handle depending on how many tabs are open: 如果我运行此代码,则根据打开的选项卡的数量,它会返回多个句柄:

 Process[] IEPROCS = Process.GetProcessesByName("iexplore");
 foreach(Process Proc in IEPROCS) {

     //output code
     Proc.MainWindowHandle.ToString();

 }

So how do I determine the handle of the tab the ActiveX is running in? 那么,如何确定运行ActiveX的选项卡的句柄?

For "Legacy" purposes I have to do this in .NET V2 so WindowsInteroptHelper is out of the question. 出于“传统”的目的,我必须在.NET V2中执行此操作,因此WindowsInteroptHelper成为不可能。

I would do this: 我会这样做:

  • Get a Win32 HWND of the control's window: IntPtr hWnd = this.Handle.ToPointer(); 获取控件窗口的Win32 HWND: IntPtr hWnd = this.Handle.ToPointer();

  • Use GetParent to walk up the parent chain of windows, until I find a window with Win32 class name TabWindowClass ( GetClassName can be used to get the name of the class). 使用GetParent可以向上移动窗口的父级链,直到找到带有Win32类名称TabWindowClass的窗口(可以使用GetClassName来获取类的名称)。

  • That would be the HWND of the wanted IE tab. 那就是想要的IE标签页的HWND。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM