GetForegroundWindow - MainWindowHandle Number是IE 11上的错误为什么? [英] GetForegroundWindow - MainWindowHandle Number is Error ON IE 11 Why?

查看:71
本文介绍了GetForegroundWindow - MainWindowHandle Number是IE 11上的错误为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

       [DllImport("user32.dll")]

        static extern IntPtr GetForegroundWindow();

        private void btnAi_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            Process[] processes = Process.GetProcesses();

            foreach (Process p in processes)
            {
                if (!p.ProcessName.Equals("Idle"))
                {
                    if (p.MainWindowHandle != IntPtr.Zero)
                    {
                        listBox1.Items.Add(p.ProcessName + "-" + p.MainWindowHandle);
                    }
                }
            }
        }



MWH = GetForegroundWindow();  // IE 11 --> 132256




有些电脑没问题 

Some Computer is Okay 

但有些计算机无法在IE 11上找到正确的代码

But Some Computer Unable to find the correct code ON IE 11

 喜欢这个↓

 Like this ↓

GetForegroundWindow()得到的数字是132256,但是进程得到两个IE 11处理程序编号是199026,2426540

GetForegroundWindow() get number is 132256, but Processes get Two IE 11 handler number is 199026, 2426540




有些计算机可以捕获正确的数字,有些计算机无法捕获正确的数字

Some computers can catch the correct number, some computers can't catch the correct number

所以我不知道问题出在哪里。

SO I don't know where the problem is.

ex:1




ex:2










推荐答案

IE (可以)使用多个进程,每个进程一个进程。这是出于安全原因。可以发挥不同的因素,包括保护模式是否开启。但这就是所有浏览器大部分工作的方式。通常,存在单个父
进程来托管子进程,并且(可能)正在使用IPC与它们进行通信。不幸的是,.NET(和Windows)不会直接暴露父子进程信息。您必须深入了解Win32 API以获取该信息。
IE (may) use multiple processes, one for each tab. This is for security reasons. Different factors can come into play including whether protected mode is on or not. But this is how all the browsers work for the most part. In general there is a single parent process that hosts the child processes and (presumably) is using IPC to communicate with them. Unfortunately .NET (and Windows) doesn't directly expose parent-child process information. You have to go digging into the Win32 API to get that information.


这篇关于GetForegroundWindow - MainWindowHandle Number是IE 11上的错误为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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