检查其他进程的文本框是否为活动控件

时间:2013-03-24 17:47:40

标签: c# vb.net winforms pinvoke

我想通过文本框句柄检查其他进程文本框控件是否是其他进程主窗口中的活动控件。

代码应如下所示:

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)?

1 个答案:

答案 0 :(得分:0)

我找到了答案:
    使用GetForegroundWindow功能获取用户当前正在使用的窗口     使用GetWindowThreadProcessId功能获取此窗口和您的窗口的ID     使用AttachThreadInput函数暂时将线程的消息队列与拥有另一个窗口的线程相关联     使用GetFocus函数获取hWnd!     再次使用AttachThreadInput功能断开与其他线程的连接 资源: http://www.codeproject.com/Articles/34752/Control-in-Focus-in-Other-Processes

相关问题