私のタスクは、フォアグラウンドウィンドウ(GetForegroundWindow APIを使用して達成)を見つけることでした。次に、フォアグラウンドウィンドウのすべての子ウィンドウ(EnumChildWindows APIを使用して達成)を含むリストを事前に入力する必要がありました。次に、マウスを検出する必要があります。カーソルはどの子ウィンドウにありますか。つまり、どの子ウィンドウ(フォアグラウンドウィンドウのボタンまたはテキストボックスの場合があります)がアクティブであるかを確認する必要があります。クリックされたChildWindowsのハンドルを取得できるAPIはありますか?フォーカスが置かれている(アクティブなフォアグラウンドウィンドウの)ChildWindowの名前だけを取得しても、それで十分です。前もって感謝します。
1 に答える
4
InPtr hwnd = GetForegroundWindow();
public static void GetAppActiveWindow(IntPtr hwnd)
{
uint remoteThreadId = GetWindowThreadProcessId(hwnd, IntPtr.Zero);
uint currentThreadId = GetCurrentThreadId();
//AttachTrheadInput is needed so we can get the handle of a focused window in another app
AttachThreadInput(remoteThreadId, currentThreadId, true);
//Get the handle of a focused window
IntPtr focussed = GetFocus();
StringBuilder activechild = new StringBuilder(256);
GetWindowText(focussed, activechild, 256);
string textchld = activechild.ToString();
if (textchld.Length > 0)
{
Console.WriteLine("The active Child window is " + textchld + " .");
}
//Now detach since we got the focused handle
AttachThreadInput(remoteThreadId, currentThreadId, false);
}
これが最終的に問題を解決したものです:)
于 2012-04-11T12:06:08.810 に答える