Are you leaving the app by clicking on another app or some other window??
Those events don't fire when you leave and return to your app. There is a windows-message you can listen for that will tell you this - it's just a bit more complicated.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Are you leaving the app by clicking on another app or some other window??
Those events don't fire when you leave and return to your app. There is a windows-message you can listen for that will tell you this - it's just a bit more complicated.
"Are you leaving the app by clicking on another app or some other window??"
yes i'm... why visual basic 6 have these events, if are ignored?
thanks
Public Sub AppFocus(ByVal v_bFocus As Boolean)
Dim i As Long, j As Long, k As Long, x As Long, y As Long, z As Long
Dim s1 As String, s2 As String, s3 As String, s4 As String, s5 As String
If v_bFocus Then
'App has just gained focus
Me.Caption = "ActivateApp; has-focus with TAB...TAG=" & tabForms.SelectedItem.Tag 'here
'Me.Caption = "ActivateApp gmodal" & gModal
If Not gModal Then 'these condition
For x = 2 To Forms.Count - 1
If tabForms.SelectedItem.Tag = CStr(Forms(x).mintTabNo) Then
' Me.Caption = "ActivateApp; has-focus TXTINPUT.TAG=" & Forms(x).txtInput.Tag & " CBOINPUT.TAG=" & Forms(x).cboInput.Tag
gfrmKeyDown(Forms(x).mintTabNo) = -1 'here
Call FocusPilot(Forms(x), 0, 0, 0, 0)
Exit For
End If
Next
End If
Else
'App has just lost focus
'Me.Caption = "ActivateApp; no-focus"
End If
End Sub
and i don't know if there is more...
can you help me complete these?
thanks
The concept is that the function APPFOCUS gets called when the app gains or loses focus. Subclassing tells windows that when that specific message (WM_ACTIVATEAPP) is "heard" to call that function in your app.
You do not need all that code that appears in APPFOCUS - that's specific to what I needed to have happen.
Put just a msgbox in that function for now - so you can see how the process itself works.
You can see that I originally had it change the FORM CAPTION - so you can see the actual event occur.
btw - careful about using this in the IDE - it will cause VB to abort out to desktop sometimes - save often.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
In a new project create a module - and put this code in it.
Code:
Option Explicit
Private 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC As Long = (-4)
Private Const WM_ACTIVATEAPP = &H1C
'm_frmHooked is the form that the subclass 'listens' in on
Private m_lPrevProc As Long, m_frmHooked As Form
Public Function WndProc(ByVal hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
'Let the window process messages as well
WndProc = CallWindowProc(m_lPrevProc, hWnd, wMsg, wParam, lParam)
'See what message has been sent to the window
If wMsg = WM_ACTIVATEAPP Then
'It's the activateapp message so call the sub on the form
Call m_frmHooked.AppFocus(CBool(wParam))
End If
End Function
Public Sub Unsubclass()
Debug.Print "UnSubClass"
Call SetWindowLong(m_frmHooked.hWnd, GWL_WNDPROC, m_lPrevProc)
Set m_frmHooked = Nothing
End Sub
Public Sub Subclass(ByRef r_frm As Form)
Debug.Print "SubClass"
Set m_frmHooked = r_frm
m_lPrevProc = SetWindowLong(r_frm.hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Now in the form itself - put this code.
Code:
Private Sub Form_Load()
Call Subclass(Me)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Unsubclass
End Sub
Public Sub AppFocus(ByVal v_bFocus As Boolean)
If v_bFocus Then
'App has just gained focus
Me.Caption = "ActivateApp; has-focus"
Else
'App has just lost focus
Me.Caption = "ActivateApp; no-focus"
End If
End Sub
You are probably best to create an .EXE to run this - as subclassing in the IDE is a bad idea.
Does this work for you??
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".