为什么Process.MainWindowTitle总是空为所有,但一个窗口? [英] Why is Process.MainWindowTitle always empty for all but one window?

查看:1168
本文介绍了为什么Process.MainWindowTitle总是空为所有,但一个窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在访问Process.MainWindowTitle如下...

When accessing Process.MainWindowTitle as follows...

Process[] processes = Process.GetProcessesByName( "iexplore" );

...然后遍历结果数组,我总是最后的 MainWindowTitle 是空的阵列中的所有,但一个项目。就我而言,我有两个Internet Explorer窗口打开,其中一个单独的标签,一个在它两个选项卡。

...and then loop over the resulting array, I always end up with the MainWindowTitle being empty for all but one item in the array. In my case I've got two Internet Explorer windows open, one with a single tab and one with two tabs in it.

运行我的code我总是得到MainWindowTitle的,我有最后一个活动的窗口和标签 - 所有的人保持空白。奇怪的是,在该MainWindowTitle充满进程ID总是一样的 - 如果我启动运行我的code之前,其他IE浏览器窗口或标签,进程ID总是相同的:

Running my code I always get the MainWindowTitle for the window and tab that I had last active - all the others remain empty. The strange thing is that the process ID in which the MainWindowTitle is filled is always the same - if I activate the other IE window or tab before running my code, the process ID is always the same:

  if ( !processes.Any() )
  {
    MessageBox.Show( "TODO - No matching process found" );
    return;
  }

  if ( processes.Count() > 1 )
  {
    foreach ( Process currentProcess in processes )
    {
      // More than one matching process found
      checkedListBox1.Items.Add( currentProcess.Id + " - " + currentProcess.MainWindowTitle + " - " + currentProcess.ProcessName );
    }

    return;
  }

因此​​,输出可能是第一次运行,如:

Output could therefore be for the first run like:

  • 4824 - - IEXPLORE
  • 3208 - - IEXPLORE
  • 4864 - 谷歌 - Windows Internet Explorer的 - IEXPLORE

下次运行(与事先选择的其他IE窗口):

Next run (with the other IE window selected beforehand):

  • 4824 - - IEXPLORE
  • 3208 - - IEXPLORE
  • 4864 - id Software公司 - 的​​Windows Internet Explorer - IEXPLORE

我读过关于<一个href="http://stackoverflow.com/questions/210504/enumerate-windows-like-alt-tab-does?answertab=votes#tab-top">this帖子,但我没有得到任何进一步的与我的问题(而且似乎进入一个有所不同的方向是这样)。

I've read about this post, but I didn't get any further with my problem (and it seems to go into a somewhat different direction anyway).

为什么我总是只能得到一个非空MainWindowTitle?

Why do I always only get one non-empty MainWindowTitle?

推荐答案

一个选项,以实现这一目标reliabely(见上述评论)是实施的 BHO - ESP。在 DWebBrowserEvents2 :: WindowStateChanged 事件是有用的在这种情况下。

One option to make this happen reliabely (see comments above) is to implement a BHO - esp. the DWebBrowserEvents2::WindowStateChanged Event is usefull in this scenario.

BHO是一堆COM接口的实现,并获得加载到浏览器进程/每个标签......实现它们在C ++ IMO最好的方式。

BHOs are implementations of a bunch of COM interfaces and get loaded into the browser process/each tab... best way to implement them is in C++ IMO.

但肯定是可以这样做的。NET(虽然不推荐):

But it is certainly possible to do so in .NET (although not recommended):

  • http://www.codeproject.com/Articles/350432/BHO-Development-using-managed-code
  • http://www.codeguru.com/csharp/.net/net_general/comcom/article.php/c19613/Build-a-Managed-BHO-and-Plug-into-the-Browser.htm
  • AddIn-Express for IE (commercial library for .NET-based BHOs)

这篇关于为什么Process.MainWindowTitle总是空为所有,但一个窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆