BUG: VB5 Focus Not Returned to MDI Form After a Dialog Is Shown

Last reviewed: August 12, 1997
Article ID: Q172111
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

In Visual Basic 4.0 and later, if a MDI Form's Enabled property is set to False before a CommonDialog (such as ShowOpen) is displayed, the focus does not return to the MDI form, even if it is set programmatically. The subsequent behavior is that instead of giving the MDI form the focus, focus is given to the last window that had focus before the MDI form.

RESOLUTION

The current workaround for this confirmed bug is to not set the MDI Form's Enabled property to False. The CommonDialog is Modal and automatically disables the MDI Form because of its Modal nature. Thus the workaround code for the code example in this article is:

   Private Sub Picture1_Click()
      CommonDialog1.ShowOpen
   End Sub

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Visual Basic. Form1 is created by default.

  2. Add a MDI Form (MDIForm1) to the Project.

  3. Make the MDI Form the Startup Form.

  4. Add a Common Dialog Control (CommonDialog1) to the MDIForm1.

  5. Add a Picture Box Control (Picture1) to the MDIForm1.

  6. Add the following code to the Picture1_Click Event:

          Private Sub Picture1_Click()
    
             MDIForm1.Enabled = False
             CommonDialog1.ShowOpen
             MDIForm1.Enabled = True
          End Sub
    
    

  7. Run the project. Note that the focus does not return to the MDIForm1. Instead the focus is sent to the next available window.

NOTE: This behavior did not occur with the Cmdialog.vbx that shipped with Visual Basic 3.0.

Keywords          : VB4ALL VB4WIN vb5all
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbbug


================================================================================


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: August 12, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.