Microsoft KB Archive/182949

= BUG: Modal Form Disabled When Launched From ActiveX Control =

Article ID: 182949

Article Last Modified on 3/10/2005

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q182949



SYMPTOMS
You open a Form from a UserControl and no object can have the focus. Users cannot click on anything, not even to close the Form.



CAUSE
If a UserControl on a Modal Form opens another Modal Form which was loaded in either the InitProperties or ReadProperties events, no object can have the focus.



RESOLUTION

 * Do not load a Form modally from the InitProperties or ReadProperties Events of a UserControl on a Modal Form.
 * Use a Timer to re-enable the window with the EnableWindow API function.



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
This problem occurs only when using the compiled ocx. Everything works as expected if the UserControl Project is added to this test Project instead of using the compiled ocx. When this problem does occur, the only way to close the Form is from the keyboard by pressing the ALT+F4 key combination. If the BorderStyle property of the Form is set to 0 - None, the process will not work and you cannot close the application gracefully.

Steps to Reproduce Behavior
 Create a New UserControl Project and name it UsrCtlModalTest.  Add a CommandButton to the UserControl, and then add the following code: Private Sub Command1_Click usrTestForm.Show vbModal, Me     End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag) ' or in Sub UserControl_InitProperties ... Load usrTestForm End Sub  Add a Form to the Project and name it usrTestForm. From the File menu, Make UsrCtlModalTest.ocx. Close and Save the UserControl Project.  Create a New Standard EXE Project. Form1 is created by default. Add a second Form to the Project. Add a CommandButton to Form1 with the following code: Form2.Show vbModal, Me                        Choose Components from the Project Menu, and then check UsrCtlModalTest and OK.</li> Add the UsrCtlModalTest control to Form2. Run the Project and click on the buttons to open both Forms.</li> Try to close the last Form by clicking on the Close button in the Control Box.

Note that no matter where you click, nothing but a beep is produced. The only way to close the Form is by pressing the ALT+F4 key combination. Once closed and reopened, it works fine. This is because you unloaded the instance of the Form that was loaded in either the InitProperties or ReadProperties Event. It works fine to Load the Form from the Click of the button.</li></ol>

Steps to Workaround Behavior
<ol> Open the UsrCtlModalTest.ocx project created above and place a Timer control on the Modal Form being launched, usrTestForm.</li> Set the Timer's Interval property to 100.</li>  Paste the following into the declarations section of usrTestForm: Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, _  ByVal fEnable As Long) As Long

Sub Form_Load Timer1.Enabled = True  ' Turn on the timer End Sub

Private Sub Timer1_Timer EnableWindow Me.hwnd, 1 Timer1.Enabled = False  ' Turn off the timer End Sub </li> Repeat the steps above to create a Standard EXE project to test the UserControl. This time the Modal From can receive focus and will close when you click on the Close button.</li></ol>

Additional query words: kbActiveX kbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport kbControl kbCtrlCreate

Keywords: kbbug kbpending KB182949

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.