将按键从TWebBrowser重定向到ParentForm的一种方法 [英] A way to redirect keypresses from TWebBrowser to the ParentForm

查看:220
本文介绍了将按键从TWebBrowser重定向到ParentForm的一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个问题。帮助格式化,如果需要,请。



上下文

我有TWebBrowser在用来表现它像一个打印机的主要形式。

因此,我加载一些HTML文本作为用户在真正的打印机做一些命令...

我希望用户能够点击并从WebBrowser中选择文本。



问题

当用户点击WebBrowser时,一些从操作中注册的快捷键不再起作用。例如,有一个快捷操作 F7 。如果用户点击WebBrowser并按F7,它不会调用我的快捷方式。

我知道这是由WebBrowser的设计。



所以,我想:我想发送每个组合键到窗体。

问题是:如何?
如果是另一个控件,我可以使用一个<$在code> OnKeyDown 事件中执行(WM_KeyDown,...)。



替代或建议也将赞赏。我过去2天非常疲倦,所以我可能会错过一些东西。

解决方案

使用<$ c实现派生TWebBrowser $ c> IDocHostUIHandler 或使用着名的 EmbeddedWB



TranslateAccelerator

$ b $中调用事件 OnTranslateAccelerator b

在brwoser实例上设置事件

检测您的密钥(s),如下所示:

 函数TBrowserPageIE.DoTranslateAccelerator(const lpMsg:PMSG; const pguidCmdGroup:PGUID; const nCmdID:DWORD):HRESULT; 
开始
结果:= S_FALSE;

if lpMsg.message = WM_KEYDOWN然后开始
if lpMsg.wParam = VK_F7然后开始
//在这里做某事...
result:= S_OK;
end;
end;
end;


First question. Help format it, if needed, please.

Context
I have a TWebBrowser in the main form that is used to behave like it was a printer.
So I load some HTML text in it as user do some commands in the real printer...
I want the user to be able to click and select text from the WebBrowser.

Problem
When the user clicks in the WebBrowser some of the shortcuts registered from the actions don't work anymore. For example, there is an action with shortcut F7. If the user clicks in the WebBrowser and presses F7, it does not invoke my shortcut.
I know that this is by design of the WebBrowser.

So, I thought: I want to send every key combination back to the form.
The question is: How?
If it was another control, I could use a perform(WM_KeyDown,...) in the OnKeyDown event.

Alternatives or suggestions would be appreciated too. I am very tired these past 2 days, so I could be missing something.

解决方案

Derivate TWebBrowser with an implementation of IDocHostUIHandler or use the famous EmbeddedWB

Implement the interface with an event OnTranslateAccelerator called in TranslateAccelerator

Set the event on your brwoser instance

Detect your key(s) like this:

function TBrowserPageIE.DoTranslateAccelerator(const lpMsg: PMSG; const pguidCmdGroup: PGUID; const nCmdID: DWORD): HRESULT;
begin
  result := S_FALSE;

  if lpMsg.message = WM_KEYDOWN then begin
    if lpMsg.wParam = VK_F7 then begin
      // do something here...
      result := S_OK;
    end;
  end;
end;

这篇关于将按键从TWebBrowser重定向到ParentForm的一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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