Checking If a Window Exist
- Is there any c++ command (or .NET it doesn't matter too me) to check if a window is active. I want a program to check every minute and a half (i know how to set a timer so that won't be the problem) if a certain window exists. If it exists then I would like to switch to the window.So my question: What is the command for checking if a window exists and what is the command to switch too it?Thanks in advanced,Chetjan
Answers
- FindWindow is declared in Winuser.h, include Windows.h, you can bring a window to the foreground using SetForegroundWindow.
- Marked As Answer bychetjan Saturday, November 07, 2009 5:06 PM
All Replies
- You can use FindWindow() to search for a window with a specific class name and/or window title.
- Proposed As Answer by.Sreedhar Thursday, November 05, 2009 5:59 AM
- Do I need any headers for that? And how do I call it after I have found it the window exists?
- FindWindow is declared in Winuser.h, include Windows.h, you can bring a window to the foreground using SetForegroundWindow.
- Marked As Answer bychetjan Saturday, November 07, 2009 5:06 PM
- I can't help but comment that this is considered a very bad idea by most programmers. If I'm typing away in Microsoft Word, I don't want to suddenly be typing input to another window that has stolen focus. If I found such a program on my computer I would go to great lengths to poison the author.
- The goal of the program is to keep me logged into my e-mail while I am away from my keyboard. I'm programming it so that I will not execute any commands unless there has been inactivity for 5 minutes. The e-mail client after being on for a certain amount of time will give a five minute log off warning. If I am temporarily away from my computer I want the program to click the stay logged on button if the message pops up (which closes the message). Is there a better way to do this Brian Muth (or anybody else)?
- Which email client are you talking about? Is it not configurable?
- It is the First Class email client. I have not been able to find any setting to disable automatic log off and have asked around to no avail. The only way I can see to avoid the annoying auto log off is to write a program. Is there any other way?
- Have you contacted FirstClass support to find out? This would be the best solution if there was a simple setting to address this issue.
Otherwise, trying to control a program through external means when it was never designed for automation is really hit or miss. Sometimes simply sending a windows message to the most derived child window (whatever that is when when program is idle for a few minutes) may be enough to fool the program to believe you are still sitting there. A tool like Spy++ can be helpful to determine what that windows message should be. - Thanks so much.


