Search code examples
winapimfckeyboard-shortcuts

How to disable Ctrl+F6, Ctrl+Tab and Ctrl+F4 in an MDI program


I need to disable Ctrl+F4 (close document), Ctrl+F6 (next pane) and Ctrl+Tab (next document) shortcuts in an MFC MDI program. These shortcuts are handled automatically by MFC (or even Win32 ?).

Is there an easy way do to this ? I was thinking to intercept the corresponding keystrokes in PreTranslateMessage, but this seems more of a hack to me.


Solution

  • The TranslateMDISysAccel Win32 function is responsible for turning those keypresses into WM_SYSCOMMAND messages. It's called as part of a "standard" MDI message loop (pseudo-code):

    while (GetMessage())
    {
        if (!TranslateMDISysAccel() && !TranslateAccelerator())
        {
            TranslateMessage();
            DispatchMessage();
        }
    }
    

    Therefore, in a pure Win32 program the solution would be to simply not call TranslateMDISysAccel as part of your message loop if you don't want those keys to be handled.

    I'm assuming that in an MFC-based program this detail is hidden from you. It would seem then that overriding the PreTranslateMessage function would be the appropriate solution. There is quite a good discussion of this technique here.