1,486
社区成员
发帖
与我相关
我的任务
分享
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function NewSetFocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Command1_Click()
'点击之后切换到文本文档上打字(打字速度不要太快,或者只点一下文本文档,光标落入里面即可)
'3秒后观察光标是否消失
Timer2.Enabled = True
End Sub
Private Sub MDIForm_Load()
Timer2.Interval = 3000
Timer2.Enabled = False
End Sub
Private Sub Timer2_Timer()
Dim lngActive As Long, lngActive2 As Long
Timer2.Enabled = False
lngActive2 = ForeWindow()
Dim SI As STARTUPINFO, PI As PROCESS_INFORMATION
SI.cb = Len(SI)
CreateProcessInternalW 0, StrPtr("popup.exe"), ByVal 0, ByVal 0, ByVal 0, ByVal 0, 0, 0, 0, SI, PI, ByVal 0
WaitForInputIdle PI.hProcess, 5000
' Shell App.Path & "\popup.exe", vbMinimizedNoFocus
' AttachThead lngActive2
End Sub
Private Function ForeWindow() As Long
Dim hForegdWnd As Long, dwCurID As Long, dwForeID As Long
Dim hActive As Long
hForegdWnd = GetForegroundWindow()
dwForeID = Abs(GetWindowThreadProcessId(hForegdWnd, 0))
dwCurID = Abs(GetCurrentThreadId())
AttachThreadInput dwForeID, dwCurID, 1
hActive = GetFocus() '输入焦点所在控件句柄
AttachThreadInput dwForeID, dwCurID, 0
ForeWindow = hActive
End Function
Private Sub AttachThead(hwnd As Long)
Dim hForegdWnd As Long, dwCurID As Long, dwForeID As Long
dwCurID = GetCurrentThreadId()
dwForeID = GetWindowThreadProcessId(hwnd, 0)
AttachThreadInput hwnd, dwCurID, 1
NewSetFocus hwnd
AttachThreadInput hwnd, dwCurID, 0
End Sub