通过标题查找 Window window 的标题是什么?
Find Window By Caption what is the caption of the window?
我必须跟踪程序的 运行 时间。
该程序公开了以下 window
同时我启动了我的程序,它在计时器中执行:
private void TimerCheckGroups_Tick(object sender, EventArgs e)
{
IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Execution");
if (windowPtr != IntPtr.Zero)
Console.Beep();<--------
}
但蜂鸣线永远不会被击中。
我是否误解了 window 标题的含义?
--添加--
我会尽量让执行阶段更清晰。
启动----> 启动我的记录器。
用户--------> 启动程序 A,程序 A 启动程序 B(不可见),程序 B(不可见)启动 window C。C 有标题执行。
当我启动dontbyteme提出的解决方案时,只出现了B程序,所以只有1个window。
简而言之
记录器:不可见,因为它是托盘程序
程序A:可见,因为它是主程序
程序 B:不可见,因为它设置为不可见
程序C:为什么不可见?!?!?!?
--感谢 JARRETT 的解决方案--
logger 保持空闲并使用定时器监视进程
程序A启动了,但没人关心它。然后程序A启动程序B
当程序 B 唤醒时,我找到 window 并开始记录
您可以尝试通过每个 window 通过 运行 获取 window 并与标题进行比较:
foreach(Window window in Application.Current.Windows)
{
if(window.Title == "Execution")
{
Console.Beep();
// ...
}
}
Title
属性就是你所说的Caption
。
以下问题解决了如何查明程序启动的时间。 Detecting the launch of a application 此外,您可以通过导入 dll 并使用 EnumWindows 在您的计算机上枚举 windows。列出了对您有帮助的示例 pInvoke。
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);
我必须跟踪程序的 运行 时间。
该程序公开了以下 window
同时我启动了我的程序,它在计时器中执行:
private void TimerCheckGroups_Tick(object sender, EventArgs e)
{
IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Execution");
if (windowPtr != IntPtr.Zero)
Console.Beep();<--------
}
但蜂鸣线永远不会被击中。 我是否误解了 window 标题的含义?
--添加-- 我会尽量让执行阶段更清晰。
启动----> 启动我的记录器。
用户--------> 启动程序 A,程序 A 启动程序 B(不可见),程序 B(不可见)启动 window C。C 有标题执行。
当我启动dontbyteme提出的解决方案时,只出现了B程序,所以只有1个window。
简而言之
记录器:不可见,因为它是托盘程序
程序A:可见,因为它是主程序
程序 B:不可见,因为它设置为不可见
程序C:为什么不可见?!?!?!?
--感谢 JARRETT 的解决方案--
logger 保持空闲并使用定时器监视进程
程序A启动了,但没人关心它。然后程序A启动程序B
当程序 B 唤醒时,我找到 window 并开始记录
您可以尝试通过每个 window 通过 运行 获取 window 并与标题进行比较:
foreach(Window window in Application.Current.Windows)
{
if(window.Title == "Execution")
{
Console.Beep();
// ...
}
}
Title
属性就是你所说的Caption
。
以下问题解决了如何查明程序启动的时间。 Detecting the launch of a application 此外,您可以通过导入 dll 并使用 EnumWindows 在您的计算机上枚举 windows。列出了对您有帮助的示例 pInvoke。
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(IntPtr hWnd);