我想通过文本框句柄检查其他进程文本框控件是否是其他进程主窗口中的活动控件。
代码应如下所示:
Dim TheMainWinDowHandle As IntPtr = Process.GetProcessesByName("proccessName")(0).MainWindowHandle
If TheMainWinDowHandle <> IntPtr.Zero Then
Dim TextBoxHandle As IntPtr = FindWindowEx(TheMainWinDowHandle, 0, "Edit", "TextBox Inner Text")
If TextBoxHandle <> IntPtr.Zero Then
Dim TheActiveHandleInTheMainWindow As IntPtr = GetActiveHandleFrom(TheMainWinDowHandle) 'TheActiveHandleInTheMainWindow = The Focused Control Handle Of "TheMainWinDow".
If TheActiveHandleInTheMainWindow = TextBoxHandle Then
MsgBox("The TextBox Is onFocus")
Else
MsgBox("The TextBox Is Not In Focus.")
End If
End If
End If
我该怎么做(c#/ vb.net)?
答案 0 :(得分:0)
我找到了答案:
使用GetForegroundWindow
功能获取用户当前正在使用的窗口
使用GetWindowThreadProcessId
功能获取此窗口和您的窗口的ID
使用AttachThreadInput
函数暂时将线程的消息队列与拥有另一个窗口的线程相关联
使用GetFocus
函数获取hWnd!
再次使用AttachThreadInput
功能断开与其他线程的连接
资源:
http://www.codeproject.com/Articles/34752/Control-in-Focus-in-Other-Processes