BUG: Deactivate Event of Non-Modal ActiveX Form Fails to Fire (170370)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
This article was previously published under Q170370 SYMPTOMS
Visual Basic versions 5.0 and higher allow developers to create in-process
ActiveX servers with non-modal forms. However, when a user switches between
a non-modal form that is part of the main application and a non-modal form
that is part of an in-process ActiveX server, the Deactivate Event of the
forms will not fire.
RESOLUTION
You can work around this limitation using any message hooking control
or AddressOf. See the REFERENCES section below for more information.
The message you need to hook is WM_ACTIVATE. When you receive WM_ACTIVATE
you should check the lower word of the wParam to see if it is equal to
WA_INACTIVE. If it is then your form is being deactivated and you can call
your deactivation code. The following code snippet shows how your message
handler would work:
Private Const WM_ACTIVATE As Long = &H6
Private Const WA_INACTIVE As Integer = 0
Private Const WA_ACTIVE As Integer = 1
Private Const WA_CLICKACTIVE As Integer = 2
Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_ACTIVATE
Dim fActive As Integer
fActive = &HFFFF& And wparam
Select Case fActive
Case WA_INACTIVE
' Call deactivation code here
Case WA_ACTIVE
' Call activation code here
Case WA_CLICKACTIVE
' Call activation code here
Case Else
End Select
Case Else
End Select
End Function NOTE: If you have third-party controls on your form, they may be
subclassing the form as well. If you try to remove your subclass in this
scenario, you could crash. In these circumstances, you can just leave your
subclass in place.
STATUS
This behavior is by design.
REFERENCES
For more information, please see the following articles in the Microsoft
Knowledge Base:
170570 HOWTO: Build a Windows Message Handler with AddressOf in VB5
168795 HOWTO: Hook Into a Window's Messages Using AddressOf
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbbug kbprb KB170370 kbAudDeveloper |
---|
|