按标题查找窗口窗口的标题是什么? [英] Find Window By Caption what is the caption of the window?
问题描述
我必须跟踪程序的运行时间.该程序公开以下窗口
I have to track the running time of a program. That program exposes the following window
同时我启动我的程序,它在计时器中执行:
At the same time I launch my program which in a timer does:
private void TimerCheckGroups_Tick(object sender, EventArgs e)
{
IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Execution");
if (windowPtr != IntPtr.Zero)
Console.Beep();<--------
}
但是哔声线永远不会被击中.我是否误解了窗口标题的含义?
But the beep line never gets hit. Have I misunderstood the meaning of a window caption?
--添加--我会尽量让执行阶段更清晰.
--ADD-- I'll try to make the execution phases clearer.
启动----> 启动我的记录器.
Startup----> launch my logger.
用户-------> 启动程序 A,启动程序 B(不可见),启动窗口 C.C 有标题执行.
User-------> launches program A that launches program B (not visible) that launches window C. C has caption Execution.
当我启动 dontbyteme 提出的解决方案时,只有 B 程序出现,所以只有 1 个窗口.
When I launch the solution proposed by dontbyteme the only the B program appears so only 1 window.
简而言之
logger:不可见,因为它是一个托盘程序
logger: not visible since it's a tray program
程序 A:可见,因为它是主程序
program A: visible since it's the main program
程序 B:不可见,因为它被设置为不可见
program B: not visible since it's set to Notvisible
程序 C:为什么不可见?!?!?!?
program C: not visible why?!?!?!?
--感谢 JARRETT 的解决方案--
--SOLUTION THANX TO JARRETT--
logger 通过计时器监控进程保持空闲
logger stays idle with a timer monitoring processes
程序 A 启动了,但没有人关心它.然后程序 A 启动程序 B
program A starts but nobody cares about it. Then program A launches program B
当程序 B 醒来时,我找到窗口并开始记录
when program B is awake i find the window and start logging
推荐答案
以下问题解决了如何确定程序何时启动.检测应用程序的启动 此外,您可以使用dll 导入并使用 EnumWindows.列出了对您有帮助的示例 pInvokes.
The following question addresses how to find out when programs launch. Detecting the launch of a application Also, you can enumerate windows on your machine with a dll import and using EnumWindows. Sample pInvokes that will help you are listed.
[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);
这篇关于按标题查找窗口窗口的标题是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!