简体   繁体   English

如何使用MainWindowHandle获取所有窗口

[英]c# How to get all windows using MainWindowHandle

Take a look at this picture: 看一下这张照片: 在此处输入图片说明

This is how i got the handle of the window enclosed by black box. 这是我得到黑框封闭的窗口的句柄的方式。

          Process[] processes = Process.GetProcessesByName("TopazChat");
          foreach (Process p in processes)
          {  

              MessageBox.Show(p.MainWindowHandle.ToString());
              List<IntPtr> test = GetChildWindows(p.MainWindowHandle);
               foreach (IntPtr IGotIt in test)
               {
                   MessageBox.Show("I got the child windows");
               }
          }

My question is: how to get the handle of the windows that was enclosed by red box? 我的问题是:如何获得被红色框包围的窗户的把手? and is there something wrong with my approach? 我的方法有问题吗?

any suggestions? 有什么建议么? I just use that approach because it is the only one that is familiar to me.. 我只是使用这种方法,因为这是我唯一熟悉的一种方法。

That other window is another a top-level window in the same process that implements one of the visible windows in the app. 另一个窗口是在同一过程中实现应用程序中一个可见窗口的另一个顶级窗口。 This is an old Delphi 7 app which implements a hidden top-level window that is outside the visible window hierarchy. 这是一个旧的Delphi 7应用,它实现了一个隐藏的顶级窗口,该窗口位于可见窗口层次结构之外。 That hidden window is the one you have found, highlighted in black, with class name TApplication. 该隐藏的窗口是您找到的那个窗口,以黑色突出显示,其类名为TApplication。

If I were you I would p/invoke a call to EnumWindows to get all the top level windows which will include the visible main windows for that app. 如果您是我,我会p /调用EnumWindows的调用,以获取所有顶级窗口,其中包括该应用程序的可见主窗口。 This would be implemented in a very similar way to your GetChildWindows method. 这将以与GetChildWindows方法非常相似的方式实现。

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

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