DOCUMENT:Q177163 24-NOV-1997 [vbwin] TITLE :BUG: Focus Doesn't Return to MDI Form After Modal Form Is Closed PRODUCT :Microsoft Visual Basic for Windows PROD/VER:WINDOWS:5.0 OPER/SYS:WINDOWS KEYWORDS:vb5all VBKBObj VBKBVB ====================================================================== --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0 --------------------------------------------------------------------- SYMPTOMS ======== An MDI child form shows a second non-MDI form modally. The second form displays a message box (or another modal form). When you close the second form after dismissing the message box, the focus does not return to the MDI child form as expected. The focus returns to the MDI child form only when the second form does not display a message box (or a modal form). RESOLUTION ========== To work around this problem, set the focus to the MDI child form after you've shown the non-MDI child. The workaround is illustrated in the MORE INFORMATION section of this article. 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 a new Standard EXE project in Visual Basic. Form1 is created by default. From the Form1 properties dialog box, set the MDIChild property to True. 2. From the Project menu, click Add MDI Form to display the Add MDI Form dialog box. Click Open to add an MDI Form to the project. 3. Add a second form to the project. 4. Add a CommandButton to each of the forms. 5. Copy the following code to the code window of Form1: Option Explicit Private Sub Form_Load() Command1.Caption = "Show Modal Form" End Sub Private Sub Command1_Click() Form2.Show vbModal 'Uncomment the following statement to work around the problem 'Me.SetFocus End Sub 6. Copy the following code to the code window of the Form2 form: Option Explicit Private Sub Form_Load() Command1.Caption = "Show Message Box." End Sub Private Sub Command1_Click() MsgBox "Displayed from the non-MDI form." End Sub 7. Press the F5 key to run the program, and then complete the following steps: - Click Show Modal Form in the MDI Child form and the second form appears. - Click Show Message Box in the second form and the message box appears (a message box is modal). - Click OK in the message box to close the message box. - Close the second form. Results: Focus does not return to the MDI child form as expected. <<>> 177096 <<>> 1 <<>> BUG: Focus Disappears After Minimizing VB Form with UserControl <<<LONGTITLE>>> BUG: Focus Disappears After Minimizing VB Form with Usercontrol <<<PRODUCT>>> vbwin <<<PRIORITY>>> 2 <<<SECURITY>>> PUBLIC <<<AUTHOR>>> mplews <<<EDITOR>>> pjRiker <<<EDITSTATUS>>> Released <<<TECH>>> JOHNEI <<<TECHSTATUS>>> Approved <<<EXPIREDATE>>> Dec 31 1999 12:00AM <<<MESSAGE>>> <<<KEYWORD>>> vb5all VBKBCtrl VBKBAX VBKBComp <<<INTERNALADMIN>>> kbDSupport kbdsd <<<QUESTION>>> <<<PRODVERNUM>>> WINDOWS:5.0 <<<COMPONENT>>> <<<TECHNOLOGY>>> <<<LINKS>>> <<<RAIDINFO>>> RADBUG:1100; VEGAS:19277 <<<INCIDENT>>> <<<SWEEPDATE>>> <<<SWEEPSTATUS>>> <<<SOLUTIONTYPE>>> <<<ISSUETYPE>>> kbbug <<<PLATFORM>>> WINDOWS <<<HARDWARE>>> <<<BOILERPLATE>>> <<<PRODUCEDVIEW>>> <<<TEXT>>> --------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual Basic Professional and Enterprise Editions for Windows, version 5.0 --------------------------------------------------------------------- SYMPTOMS ======== If a form containing a UserControl is minimized in a Visual Basic application, focus does not shift to another application. The expected behavior is for the next application in the task order to receive the focus. 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 a new Standard EXE project in Visual Basic 5.0. Form1 is created by default. 2. Click Add UserControl on the Project menu. 3. Close the UserControl designer window. 4. Add the UserControl to Form1. 5. From the File menu, chose Make Project1.exe. 6. Start another application. 7. Run the exe that you created in step 5. 8. Minimize the Visual Basic Application. Note that focus does not shift to the application started in step 6 as expected. Additional query words: focus active inactive titlebar ====================================================================== Keywords : vb5all VBKBObj VBKBVB Version : WINDOWS: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. Copyright Microsoft Corporation 1997.