Zjištění ztráty a získání focusu

Postup:
Založte nový projekt, přidejte modul a v něm deklarujte:

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 WM_ACTIVATEAPP = &H1C
Private Const GWL_WNDPROC =    -4
Public lpPrevWndProc As Long
Public gHW As Long 

Public Sub Hook()

lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, _
    AddressOf WindowProc) 

End Sub

Public Sub Unhook()

Dim temp As Long

temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)

End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

'Test události ActivateApp
If uMsg = WM_ACTIVATEAPP Then
If wParam = 0 Then
'Aplikace získala focus
Form1.Caption = "Získán focus"
Else
Form1.Caption = "Ztracen focus"
End If
End If 

WindowProc =  CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam) 

End Function


Do formuláře zapište:
Option Explicit

Sub Form_Load()

    gHW = Me.hwnd   
    Hook    
    
End Sub

Private Sub Form_Unload(Cancel As Integer)

    Unhook
    
End Sub

Spusťte projekt a otestujte.

Zpět

Autor: The Bozena

iReklama.cz - nový reklamní systém
iReklama.cz - nový reklamní systém