如何确定另一个应用程序的窗口是否可见?
我最近获得了 WinX DVD Ripper Platinum 的许可证,但令我恼火的是,当它完成 DVD 翻录后,它并没有告诉我这一点。没有弹出窗口,没有系统“蜂鸣声”——什么也没有。进度对话框将直接关闭。主窗口甚至没有聚焦自己...
为了加快我的 DVD 翻录过程,我正在制作一个简单的控制台应用程序(使用 C# 和 VS2010):
- 查找名为“WinX_DVD_Ripper_Platinum”的进程的句柄(该进程WinX DVD Ripper Platinum 软件的名称)
- 使用 pinvoke.net 上的此示例
- 启动一个
System.Timers.Timer
实例,检查(或应该检查)进度对话框是否已每 5 秒关闭一次(使用GetWindowLong
函数, 使用System.Console.Beep
方法播放 - 几声蜂鸣声,告诉用户 rip 已完成。计时器会自动重置,执行检查(如果对话框已关闭,则重复蜂鸣声)。每 5 秒一次,直到用户按下控制台窗口中的某个键。
步骤 1、2 和 4 工作正常,但我在步骤 3 中遇到问题 - 我的问题是,哪个 窗口样式常量 我应该使用它来检查窗口是否可见吗? (WS_VISIBLE 不起作用...)
有关更多详细信息,这是我用来检查对话框可见性的函数:
private static bool IsWindowVisible(IntPtr hwnd)
{
var style = GetWindowLong(hwnd, GWL.GWL_EXSTYLE);
var visible = style & (WS flag goes here);
return visible != 0;
}
I recently obtained a license for WinX DVD Ripper Platinum, and am annoyed by the fact that, when it's done ripping a DVD, it doesn't tell me so. There's no popup, no system "beep"- nothing. The progress dialog simply closes. The main window doesn't even focus itself...
To speed up my DVD-ripping proccess, I'm making a simple console application (using C# and VS2010) that:
- Finds the handle of the process named "WinX_DVD_Ripper_Platinum" (the process name of the WinX DVD Ripper Platinum software)
- Finds the handle of the progress dialog on that process using the
GetChildWindows
method defined in this sample at pinvoke.net - Starts a
System.Timers.Timer
instance that checks (or is supposed to check) whether the progress dialog has closed every 5 seconds (using theGetWindowLong
function, and - Plays a few beeps with the
System.Console.Beep
method to tell the user that the rip is complete. The timer auto-resets, performing the check (or repeating the beep if the dialog has closed) every 5 seconds until the user presses a key in the console window.
Steps 1, 2, and 4 are working fine, but I'm having problems with step 3- this, my question is, which of the window style constants should I use to check if the window is visible? (WS_VISIBLE did NOT work...)
For more details, this is the function I'm using to check the dialog's visibility:
private static bool IsWindowVisible(IntPtr hwnd)
{
var style = GetWindowLong(hwnd, GWL.GWL_EXSTYLE);
var visible = style & (WS flag goes here);
return visible != 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过使用 IsWindowVisible()反而?
Have you tried using IsWindowVisible() instead?