PRB: Deactivate Event of Non-Modal ActiveX Form Fails to FireLast reviewed: November 26, 1997Article ID: Q170370 |
The information in this article applies to:
SYMPTOMSVisual Basic 5.0 allows 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.
RESOLUTIONYou 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 FunctionNOTE: If you have third-party controls on your for, they may be subclassing the form as well. If you try to remove your subclass in this scenari, you could crash. In these circumstances, you can just leave your subclass in place.
STATUSThis behavior is by design.
MORE INFORMATIONThe Visual Basic 5.0 help topic for the Deactivate event explains the following: "If an .exe file built by Visual Basic displays a dialog box created by a .dll file also built in Visual Basic, the .exe file's form will get the Deactivate and LostFocus events. This may be unexpected, because you should not get the Deactivate event:
"You should not get a Deactivate event if the focus is changed to another form that is not part of the VB Project containing the form that currently has the focus."
Steps to Reproduce Behavior
REFERENCESFor more information, please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q170570 TITLE : HOWTO: Build a Windows Message Handler with AddressOf in VB5 ARTICLE-ID: Q168795 TITLE : HOWTO: Hook Into a Window's Messages Using AddressOf Keywords : vb5all VBKBAutomation VBKBAX VBKBComp VBKBDLL Version : 5.0 Platform : WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |