窗口是从程序创建的 [英] Window was created from a program

查看:71
本文介绍了窗口是从程序创建的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测程序创建的窗口?使用c ++.

我有一个C ++源程序,它将检测窗口弹出窗口,但不会检测该程序产生的窗口弹出窗口.

如果创建的窗口未显示在任务栏中,则C ++源程序将无法检测到它.



当某个程序有一个窗口弹出窗口时,我想听到声音,这就是为什么我要制作一个C ++程序来检测该弹出窗口何时弹出的原因.

How can I detect a window created that a program has created? Using c++.

I have a C++ source program that will detect window popups, but it will not detect window popups that a program makes.

If the window created does not show up in the task bar then the C++ source program will not detect it.



When a certain program has a window popup I want to hear a sound, which is why I want to make a C++ program to detect when this popup pops up.

推荐答案

如果您要做的只是检测何时可以看到另一个程序的某个窗口,那么几乎可以确定您不应该安装全局挂钩和其他奇特的东西.我将编写一个在后台运行的程序,并定期检查(例如,每半秒一次)窗口是否可见,并且当这种情况从假"变为真"时,您会播放声音.因此您的程序应如下所示:
If all you want to do is detecting when a certain window of another program has been made visible then its almost sure that you shouldn''t install global hooks and other fancy stuff. I would write a program that runs in the background and periodically checks (for example every half seconds) if the window has become visible or not and you play a sound when this condition changes from false into true. So your program should look like this:
bool currently_visible = false;

for (;;)
{
    bool visible = IsThatWindowVisible();
    if (!currently_visible && visible)
        PlayNotificationSound();
    currently_visible = visible;
    if (exit_requested)
        break;
    Sleep_half_second();
}



除此之外,您只需要编写一个函数:bool IsThatWindowVisible().如果可以通过标题栏文本或窗口类(可以通过spy ++程序找到窗口类)来识别窗口,因为这是最好的,因为这样就可以使用 EnumWindows() [



All you h have to write besides this is a function: bool IsThatWindowVisible(). If you can identify the window by its titlebar text or by its window class (you can find out the windowclass with the spy++ program) that is the best because then you can use FindWindow()[^] to check if the window exists and when you have the HWND to that window you can do additional checking on the window (for example if it is visible, if it has a certain value in one of its editboxes/labels - you can find out which is the control id of its child controls with spy++).
If you can not detect the window by its titlebar or window class then you have to use EnumWindows()[^] to iterate over all windows and check all HWNDs to find out if its the right HWND or not (for example by checking if its have a child control with control_id==XXX and window_text=="blahblah" and window_class=="Button").


看看这个
Take a look at this link[^], probably will help you.

Good luck.


这篇关于窗口是从程序创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆