在web浏览器中的WPF中禁用上下文菜单
我有一个WPF应用程序,是要在一个小亭运行,带有触摸屏的PC上。该应用程序运行在全屏模式下,隐藏的操作系统。在我的网页我有一个WebBrowser控件,它允许用户查看某些网页(导航仅限于某些页面)。 由于计算机将被放置在一个公共点我不能让用户访问操作系统。关键是,触摸屏允许使用右键点击网页浏览器,并最终导致任务栏出现......不好..!
I have a WPF App that is going to run on a kiosk, on a PC with a touchscreen. The App runs in fullscreen mode, to hide the OS. On one of my pages I have a WebBrowser control that allows a user to view some web pages (navigation is limited to some pages). Since the computer will be placed in a public spot I mustn't let the user access the operating system. The thing is, the touchscreen allows for a right click on the web browser, and that eventually leads to the task bar appearing... not good..!
我一直试图禁用对过去的日子的上下文菜单中没有取得多大成功。基本上,我在哪里,现在是:
I've been trying to disable that context menu for the past days without much success. Basically where i'm at right now is:
-
添加一个COM引用shdocvw.dll中得到IWebBrowser2接口(需要禁用新窗口的启动。
Added a COM reference to SHDocVw.dll to get the IWebBrowser2 interface (needed to disable the launching of new windows.
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("6d5140c1-7436-11ce-8034-00aa006009fa")]
internal interface IServiceProvider
{
[return: MarshalAs(UnmanagedType.IUnknown)]
object QueryService(ref Guid guidService, ref Guid riid);
}
static readonly Guid SID_SWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
取的IWebBrowser2接口
Fetch the IWEbBrowser2 interface
IServiceProvider _serviceProvider = null;
if (_browser.Document != null)
{
_serviceProvider = (IServiceProvider)_browser.Document;
Guid _serviceGuid = SID_SWebBrowserApp;
Guid _iid = typeof(SHDocVw.IWebBrowser2).GUID;
SHDocVw.IWebBrowser2 _webBrowser = (SHDocVw.IWebBrowser2)_serviceProvider.QueryService(ref _serviceGuid, ref _iid);
和尝试,并禁止对文档的oncontextmenu。
And try and disable the oncontextmenu on the document.
HTMLDocument doc = _webBrowser.Document as HTMLDocument;
mshtml.HTMLDocumentEvents2_Event ev = doc as mshtml.HTMLDocumentEvents2_Event;
ev.oncontextmenu += (arg) => { return false; };
到目前为止,还没有sucess ...任何想法?
So far, no sucess... any ideas?
在此先感谢。
添加一个oncontextmenu属性添加到文档body标签为我工作。
Adding an oncontextmenu attribute to the document body tag worked for me.
<body oncontextmenu="return false;">
从这篇文章在这里。 http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/
From this article here. http://social.msdn.microsoft.com/forums/en-US/wpf/thread/7c283faf-16c8-4b4e-a362-f292e3032abb/