|
|
|
VB forms exposes the Activate and Deactivate events, which fire when the form gets and loses the focus because the user has clicked on another form of the same application. However, VB doesn't fire any event when the user clicks on a form that belongs to another Windows application. In some cases this can be a problem, because your program might rely on that that has been gathered when the form has been loaded - for example, the list of files in a given directory - and you can't be 100% sure that the data hasn't been modified by the user (for example, by deleting the files from Explorer).
To get a notification when the application as a whole gets or loses the input focus, you must subclass a form in your application, and watch for the WM_ACTIVATEAPP message. When this message is received, the wParam argument holds zero if the application is losing the focus, or a non-zero value if the application is getting the input focus. This is the code that does the trick: |
Click here to copy the following block |
Const WM_ACTIVATEAPP = &H1C
Dim WithEvents FormHook As MsgHook
Private Sub Form_Load() Set FormHook = New MsgHook FormHook.StartSubclass hWnd End Sub
Private Sub FormHook_AfterMessage(ByVal uMsg As Long, ByVal wParam As Long, _ ByVal lParam As Long, retValue As Long) If uMsg = WM_ACTIVATEAPP Then If wParam Then Else End If End If End Sub |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|