PRB: Accelerator Keys Don't Work with Disabled MDI Form

Last reviewed: October 30, 1995
Article ID: Q129804
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0
  • Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0

SYMPTOMS

When a MDI Form is programmatically disabled (Form1.Enabled = False), accelerator keys on the MDI Parent form will not respond to user input.

CAUSE

By disabling the window with the keyboard focus, you now have a disabled window with the focus. Because it has the focus, all keystrokes are directed to it, but because it is disabled, those keystrokes are not processed. This is true even for accelerators on the MDI parent form.

RESOLUTION

This behavior exists in both versions 3.0 and 4.0 of Microsoft Visual Basic for Windows. This is, in fact, standard Windows MDI behavior.

The solution is to always move the focus off the MDI child form when it becomes disabled programmatically. If the focus is on a disabled MDI child, the accelerator keys will not work under Windows, because Windows doesn't send up the WM_KEYDOWN message that Visual Basic would have to process for the accelerator's keystroke.

STATUS

This behavior is by design. This is standard Windows MDI form behavior.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a new MDI form to your project (MDIForm1).

  3. Add two menu items to MDIForm1 using the following as a guide:

       Menu       Property     Value
       ------------------------------
       mnuTop     Caption      Top
       mnuTop     Name         mnuTop
    
       mnuSub1    Caption      Sub1
       mnuSub1    Name         mnuSub1
    
    

  4. Indent mnuSub1 making it a sub-menu of mnuTop by pressing the right arrow button on the Menu Editor.

  5. Assign the ShortCut key CTRL+A to mnuSub1.

  6. Add the following code to the mnuSub1_Click event:

       Sub mnuSub1_Click()
          Msgbox "Accelerator Key Responded."
       End Sub
    
    

  7. On Form1, add a command button (Command1).

  8. Add the following code to Command1_Click() event:

       Sub Command1_Click()
          Me.Enabled = False
       End Sub
    
    

  9. Start the program by choosing Start from the Run menu or by pressing the F5 key.

  10. Click the Command1 button on Form1. Form1 becomes disabled, and it has

        the focus.
    

  11. Press CTRL+A. The accelerator menu on MDIForm1 does not respond.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbprb
KBSubcategory: PrgCrtlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.