0

他のプロセスのテキスト ボックス コントロールが、テキスト ボックス ハンドルによって他のプロセスのメイン ウィンドウでアクティブなコントロールであるかどうかを確認したい。

コードは次のようになります。

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

4

1 に答える 1

0

私は答えを見つけました: 関数を
使用GetForegroundWindowして、ユーザーが現在作業しているウィンドウを取得します。
関数を使用してGetWindowThreadProcessId、このウィンドウと自分のウィンドウの両方の ID を取得します。
関数を使用してAttachThreadInput、スレッドのメッセージ キューを他のウィンドウを所有するスレッドに一時的に関連付けます。
関数を使用しGetFocusて hWnd! を取得します。関数を再度使用してAttachThreadInput、他のスレッドから切断します。
ソース: http://www.codeproject.com/Articles/34752/Control-in-Focus-in-Other-Processes

于 2013-03-24T20:13:10.423 に答える