Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 10-Aug-12 20:11pm
v3
Comments
[no name] 10-Aug-12 18:35pm    
What is it exactly that you are trying to do?

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:
C++
bool currently_visible = false;

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


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").
 
Share this answer
 
Take a look at this link[^], probably will help you.

Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900