|
-
Apr 4th, 2001, 10:48 PM
#1
Thread Starter
Addicted Member
I need to have an event occur whenever someone multitasks to another program window. I thought that a move off of the program window would throw this:
Private Sub Form_LostFocus()
MsgBox "selected another window", vbOKOnly
End Sub
But apparently not... Any ideas?
-
Apr 4th, 2001, 10:51 PM
#2
PowerPoster
Will not fire when the focus shifts to another prog outside of Visual Basic.
-
Apr 4th, 2001, 10:52 PM
#3
Addicted Member
Might try Form_Deactivate
-
Apr 4th, 2001, 11:11 PM
#4
Thread Starter
Addicted Member
Nope
Nope
Private Sub Form_Deactivate()
MsgBox "selected another window", vbOKOnly
End Sub
Doesn't work either, any other ideas?
-
Apr 4th, 2001, 11:16 PM
#5
I'm going to guess and say that a modal form attached to a specific hWnd (ie: a message box), may not display the the app or form loses focus. Does it worl using Debug.Print statements?
- gaffa
-
Apr 4th, 2001, 11:21 PM
#6
Thread Starter
Addicted Member
hummm... I think I see what your saying.... but no the debug.print doesn't work either
-
Apr 4th, 2001, 11:22 PM
#7
PowerPoster
Seems like you may have to subclass the window and catch the lost focus message.
-
Apr 4th, 2001, 11:25 PM
#8
Thread Starter
Addicted Member
FOCUS_EVENT_RECORD ??
perhaps, but that coud be fairly messy with this specific program, I just consulted my win 32 api's and found this gem, does this look like what I'm going for here?
-
Apr 4th, 2001, 11:31 PM
#9
You must subclass to detect the Lost_Focus of a form.
Code:
Option Explicit
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal _
ndx As Long, ByVal newValue As Long) As Long
Public 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
' This is used with the SetWindowLong API function.
Public Const GWL_WNDPROC = -4
Public Const WM_KILLFOCUS = &H8
Dim saveHWnd As Long ' The handle of the subclassed window.
Dim oldProcAddr As Long ' The address of the original window procedure
Sub StartSubclassing(ByVal hWnd As Long)
saveHWnd = hWnd
oldProcAddr = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Sub StopSubclassing()
SetWindowLong saveHWnd, GWL_WNDPROC, oldProcAddr
End Sub
Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
' Send the message to the original window procedure, and then
' return Windows the return value from the original procedure.
WndProc = CallWindowProc(oldProcAddr, hWnd, uMsg, wParam, lParam)
Select Case uMsg
Case WM_KILLFOCUS
Debug.Print "Form has lost focus"
End Select
End Function
Private Sub Form_Load()
StartSubclassing Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
StopSubclassing
End Sub
-
Apr 5th, 2001, 03:15 AM
#10
Fanatic Member
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|