Try this...
VB Code:
Option Explicit Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, _ ByVal idAttachTo As Long, _ ByVal fAttach As Long) _ As Long Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function GetFocus Lib "user32" () As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _ lpdwProcessId As Long) _ As Long Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long Private Sub Timer1_Timer() Dim hFore As Long, hFocus As Long hFocus = GetFocus If hFocus = 0 Then hFore = GetForegroundWindow() Call AttachThreadInput(GetWindowThreadProcessId(hFore, 0&), GetCurrentThreadId, True) hFocus = GetFocus Call AttachThreadInput(GetWindowThreadProcessId(hFore, 0&), GetCurrentThreadId, False) End If Me.Caption = hFocus End Sub
I put it in a timer to make sure it actually worked. It seems to.




Reply With Quote