2012-04-05 93 views
0

我正在開發一個需要顯示由第三方服務返回的HTML的項目。我目前使用WPF WebBrowser來顯示此輸出。然而,這在我的客戶眼中造成了潛在的安全問題。當焦點被設置爲這種控制可以通過使用按Ctrl +ñ通過使用CTRL +Ø打開Internet Explorer中打開的任何網頁。我的應用程序針對類似自助亭的環境(終端服務)。撰寫WebBrowser COM事件的問題

在過去,我使用了WinForms WebBrowser控件,並且能夠通過COM沉入事件中,但這些策略似乎不適用於WPF版本。我的開發合作伙伴堅持認爲,我們開發純WPF應用程序,而不是在WinForms選項中混合。

有沒有人成功登入WPF WebBrowserIWebBrowserEvets2 COM接口?我已經能夠將WebBrowser.Document投到IWebBrowser,但沒有到我需要的地方。

請幫助我挖掘事件,以便我可以阻止用戶創建新窗口和其他可能導致我的客戶「安全」問題的事件。還是有更好的控制來執行HTML和基本導航的呈現?

由於提前,
傑羅德

+0

這不是不可能的,它只是在WPF很多醜陋的。在谷歌查詢中鍵入「wpf newwindow2」,採取第一擊。 – 2012-04-05 15:50:36

回答

0

你可以在這裏嘗試使用Windows鉤子。找到瀏覽器窗口併爲其安裝正確的鍵盤鉤子。這應的外部對你會有所幫助:

[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)] 
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, IntPtr windowTitle); 
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] 
private static extern IntPtr SetWindowsHookEx(Int32 idHook, HookProc lpfn, IntPtr hInstance, Int32 threadId); 

這裏是一個示例如何使用這些,但你必須根據自己的需要來實現KeyboardHookProcedure。

private IntPtr FindExplorerWindow() 
{ 
    IntPtr wnd = Browser.Handle; 
    if (wnd != IntPtr.Zero) 
    { 
     wnd = FindWindowEx(wnd, IntPtr.Zero, "Shell DocObject View", IntPtr.Zero); 
     if (wnd != IntPtr.Zero) 
     { 
      wnd = FindWindowEx(wnd, IntPtr.Zero, "Internet Explorer_Server", IntPtr.Zero); 
      return wnd; 
     } 
    } 
    return IntPtr.Zero; 
} 

private void InstallHook() 
{ 
    if (_hHook.ToInt32() > 0) return; 

    IntPtr wnd = FindExplorerWindow(); 
    if (wnd != IntPtr.Zero) 
    { 
     if (_hookProc == null) 
     { 
      _hookProc = new HookProc(KeyboardHookProcedure); 
     } 
     _hHook = SetWindowsHookEx(WH_KEYBOARD, _hookProc, (IntPtr)0, GetCurrentThreadId()); 
    } 
} 

祝你好運!