by Anonymous (267 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 25th November 1998
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Determine when your visual basic application gains or loses focus.
API Declarations
Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const WM_ACTIVATEAPP = &H1C
Public Const GWL_WNDPROC = -4
Global lpPrevWndProc As Long
Global gHW As Long
Sub Form_Load()
'Store handle to this form's window
gHW = Me.hWnd
'Call procedure to begin capturing messages for this window
Hook
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Call procedure to stop intercepting the messages for this window
Unhook
End Sub
'******************************************************************
'Paste the following code into the main module:
Public Sub Hook()
'Establish a hook to capture messages to this window
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
AddressOf WindowProc)
End Sub
Public Sub Unhook()
Dim temp As Long
'Reset the message handler for this window
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub
No comments have been posted about Determine when your visual basic application gains or loses focus.. Why not be the first to post a comment about Determine when your visual basic application gains or loses focus..