c00000fd
c00000fd

Reputation: 22265

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.

Upvotes: 1

Views: 1018

Answers (1)

travisco_nabisco
travisco_nabisco

Reputation: 65

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

Upvotes: 1

Related Questions