AllowSetForegroundWindow &SetForegroundWindow:NPAPI 插件想要允许桌面应用程序没有成功 [英] AllowSetForegroundWindow & SetForegroundWindow: NPAPI plug-in wants to allow a desktop application with no success

查看:23
本文介绍了AllowSetForegroundWindow &SetForegroundWindow:NPAPI 插件想要允许桌面应用程序没有成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:一个用 C++ 编写的网络浏览器插件和一个用 C# 编写的 Windows 应用程序.它们通过命名管道进行通信.该插件指示 C# 应用程序打开一个文件(假设该文件是一个 .txt 并在记事本中打开).

Here it's what I have: a web browser plug-in written in C++ and a Windows application written in C#. They communicate through a named pipe. The plug-in instructs the C# application to open a file (suppose that the file is a .txt and it opens in Notepad).

一旦 C# 应用程序收到命令,它就会打开文件,但记事本没有显示在前台,这是不可接受的,我必须在前台打开记事本.

Once the C# application is given the command, it opens the file but Notepad doesn't show in the foreground, which isn't acceptable, I must open Notepad in the foreground.

我修改了 C# 应用程序,以便它调用 SetForegroundWindow 函数.这次记事本没有在前台打开,但是任务栏闪烁.

I modified the C# application so that it calls the SetForegroundWindow function. This time Notepad didn't open in the foreground, but the taskbar flashes.

在阅读了 SetForegroundWindow 的文档和许多文章后,我想现在我明白了问题所在:C# 应用程序无法将记事本带到前台,因为它不是前台进程, 浏览器是 (?).

After reading the documentation for SetForegroundWindow and many articles I think that now I understand what the problem is: the C# application can't bring Notepad to the foreground because it wasn't the the foreground process, the browser was (?).

阅读本文后:

"一个可以设置前台窗口的进程可以启用另一个通过调用设置前景窗口的过程AllowSetForegroundWindow 函数."

"A process that can set the foreground window can enable another process to set the foreground window by calling the AllowSetForegroundWindow function."

我决定修改插件.

这次插件调用了 AllowSetForegroundWindow 函数,将 ASFW_ANY 作为参数传递(我知道,ASFW_ANY 可能有风险,但我想确保 AllowSetForegroundWindow 会这样做).

This time the plug-in calls the AllowSetForegroundWindow function passing ASFW_ANY as a parameter (I know, ASFW_ANY could be risky, but I wanted to make sure that AllowSetForegroundWindow would do it).

在对插件进行修改后,我对其进行了测试,并且成功了!(歌剧 12.02).然后我在 Internet Explorer 上对其进行了测试,它也能正常工作.但是当我在 Firefox 和 Chrome 中对其进行测试时,问题就出现了.C# 应用程序无法将记事本置于前台.我注意到对于那些浏览器,AllowSetForegroundWindow 函数返回 false.

After I did the modification to the plug-in I tested it and it worked! (Opera 12.02). Then I tested it on Internet Explorer and it worked too. But the problem came when I tested it in Firefox and Chrome. The C# application didn't have the ability to bring Notepad to the foreground. I noticed that for those browsers the AllowSetForegroundWindow function was returning false.

所以我开始调查,我得出的结论可能是因为 Firefox 使用的插件容器.我想到了一个想法:它在 Opera 12.02 中工作,但他们没有插件容器,尽管他们在 Opera 12.00 中做到了.所以我下载了Opera 12.00,我做了测试,它失败了,这让我得出结论,插件容器是罪魁祸首.

So I started investigating and I come to the conclusion that maybe it's because the plugin container that Firefox uses. An idea came to my mind: it worked in Opera 12.02, but they don't have a plugin container, although they did in Opera 12.00. So I downloaded Opera 12.00, I did the test and it failed, which makes me conclude that the plugin container is the culprit.

问题是:我怎样才能给 C# 应用程序设置前景的能力?

The question is: how can I give to the C# application the ability to set foreground?

我不知道如何继续,我想我尝试了所有合法的方式.AllowSetForegroundWindow &SetForegroundWindow 似乎不适用于此处.

I don't know how to continue, and I think that I tried all the legitimate ways. The AllowSetForegroundWindow & SetForegroundWindow seems to not apply here.

推荐答案

您很可能无法从插件中赋予 C# 应用程序这种能力,因为插件进程也不是前台进程——它实际上运行在不同的过程,至少在您可用的几个浏览器上.在 IE 上,您不是,但您处于低完整性过程中,因此您自己启动该过程将 需要一个注册表项,指定可以启动该应用程序.

You most likely can't give the C# application that ability from the plugin because the plugin process isn't the foreground process either -- it's actually running in a different process, at least on several of the browsers available to you. On IE you aren't, but you are in a low integrity process so launching the process yourself would require a registry entry specifying that it's okay to launch that application.

我不得不同意你的看法——我认为你已经尝试了所有合法的方法,但这是不可能的.哎呀,即使是安装人员也经常在最近版本的 Windows 中在后台打开重要的窗口.

I have to agree with you -- I think you have tried all the legitimate ways and it just isn't possible. Heck, even installers often end up opening important windows in the background in recent versions of windows.

这篇关于AllowSetForegroundWindow &SetForegroundWindow:NPAPI 插件想要允许桌面应用程序没有成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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