简体   繁体   English

禁用MFC Web浏览器控件中的键盘快捷方式的方法

[英]Ways to disable keyboard shortcuts in MFC web browser control

I added the MFC's web browser control into my dialog-based MFC project that gave me capabilities of the IE web browser. 我将MFC的Web浏览器控件添加到了基于对话框的MFC项目中,该项目为我提供了IE Web浏览器的功能。 It works fine, except that I've encountered one issue. 它工作正常,但我遇到了一个问题。 The IE control comes with its own keyboard shortcuts, for instance F5 for refresh, or Ctrl+P for print, or Ctrl+O for open, etc. I do not need those because I load it up internally & it should not support most of IE browser functionalities. IE控件带有自己的键盘快捷键,例如F5进行刷新,或Ctrl + P进行打印,或Ctrl + O进行打开等。我不需要这些,因为我是在内部加载的,它不支持大多数IE浏览器功能。 The question is how to disable those keyboard shortcuts? 问题是如何禁用这些键盘快捷键?

PS. PS。 Note that I do not want to disable all keyboard input for this control. 请注意,我不想为此控件禁用所有键盘输入。 For instance, I would want users to be able to scroll it using arrow keys, or page-up, page-down, etc. 例如,我希望用户能够使用箭头键或向上翻页,向下翻页等来滚动它。

I believe you are going to have to override the TranslateAccelerator method. 我相信您将不得不重写TranslateAccelerator方法。 There is not a single property that can be set to disable keyboard shortcuts when using the MFC WebBrowser Control. 使用MFC WebBrowser控件时,没有一个可以设置为禁用键盘快捷键的属性。

The code provided disables the handling of the F5 key, you will have to implement each shortcut/accelerator you wish to disable within the overridden TranslateAccelerator. 提供的代码禁用了F5键的处理,您将必须在覆盖的TranslateAccelerator中实现要禁用的每个快捷方式/加速器。

BrowserControl::TranslateAccelerator(MSG *pMsg, DWORD dwFlags)
{
    HRESULT result= S_FALSE;

    if (pMsg && pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F5) {
        // Return S_OK to indicate no more handling is needed on the message
        result= S_OK;
    }
    return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM