我的任务是找到前台窗口(使用GetForegroundWindow API完成),然后我需要预填一个列表,该列表包含前台窗口的所有子窗口(使用EnumChildWindows API完成)。现在我需要检测鼠标光标位于哪个子窗口上,即我需要找出哪个子窗口(可能是前台窗口中的按钮或文本框)处于活动状态。 有没有一些API可以获取已单击的子窗口的句柄? 即使我只能得到活动前台窗口的子窗口名称,对我来说也足够了。 提前感谢。
我的任务是找到前台窗口(使用GetForegroundWindow API完成),然后我需要预填一个列表,该列表包含前台窗口的所有子窗口(使用EnumChildWindows API完成)。现在我需要检测鼠标光标位于哪个子窗口上,即我需要找出哪个子窗口(可能是前台窗口中的按钮或文本框)处于活动状态。 有没有一些API可以获取已单击的子窗口的句柄? 即使我只能得到活动前台窗口的子窗口名称,对我来说也足够了。 提前感谢。
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);
}