【问题标题】:Find Window By Caption what is the caption of the window?Find Window By Caption 窗口的标题是什么?
【发布时间】:2015-12-22 13:37:30
【问题描述】:

我必须跟踪程序的运行时间。 该程序公开以下窗口

同时我启动了我的程序,它在计时器中执行:

private void TimerCheckGroups_Tick(object sender, EventArgs e)
{
  IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Execution");
  if (windowPtr != IntPtr.Zero)
    Console.Beep();<--------
}

但是蜂鸣线永远不会被击中。 我是否误解了窗口标题的含义?

--添加-- 我会尽量让执行阶段更清晰。

启动---->启动我的记录器。

用户-------> 启动程序 A 启动程序 B(不可见)启动窗口 C。C 有标题执行。

当我启动 dontbyteme 提出的解决方案时,只出现 B 程序,所以只有 1 个窗口。

总之

  • 记录器:不可见,因为它是一个托盘程序

  • 程序 A:可见,因为它是主程序

  • 程序 B:不可见,因为它设置为不可见

  • 程序 C:为什么不可见?!?!?!?


--JARRETT 的解决方案--

  • 记录器通过计时器监控进程保持空闲

  • 程序 A 启动,但没有人关心它。然后程序 A 启动程序 B

  • 当程序 B 唤醒时,我找到窗口并开始记录

【问题讨论】:

  • 你能让你的程序启动执行程序吗?如果您必须手动启动这两个程序,您的时间将不正确。此外,通过让您的跟踪程序启动执行程序,您可以准确地知道它何时开始。
  • 不,我不能。具有窗口执行的程序由用户启动。虽然我的程序是一个记录器,所以它是在窗口启动时启动的。
  • 根据您对编组的舒适程度,您是否查看过`EnumWindows,我已经使用它来查找打开的窗口。它在 user32.dll 中。这将为您提供打开的窗口,但在知道新程序已启动时无法解决。
  • 另外,这篇文章可能对你有用。 stackoverflow.com/questions/649900/…
  • @JarrettRobertson thanx 是 WPF 的吗?

标签: c# wpf window caption


【解决方案1】:

以下问题解决了如何确定程序何时启动。 Detecting the launch of a application 此外,您可以通过 dll 导入和使用 EnumWindows 枚举计算机上的窗口。列出了可以帮助您的示例 pInvokes。

    [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);

【讨论】:

  • 所以问题与时间有关,请参阅我的编辑,因为我已按照您的提示找到解决方案。我希望您发布一个解决方案,说明该问题与同时启动两个程序有关。我认为你应得的。
【解决方案2】:

您可以尝试通过运行每个窗口并与标题进行比较来获取窗口:

    foreach(Window window in Application.Current.Windows)
    {
        if(window.Title == "Execution")
        {
            Console.Beep();
            // ...
        }
    }

Title 属性就是您所说的Caption

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 2011-01-14
    • 2016-10-12
    • 1970-01-01
    • 2021-06-11
    • 2011-06-30
    • 1970-01-01
    相关资源
    最近更新 更多