简体   繁体   中英

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. 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. The question is how to disable those keyboard shortcuts?

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. There is not a single property that can be set to disable keyboard shortcuts when using the MFC WebBrowser Control.

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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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