Ask a questionAsk a question
 

AnswerChecking If a Window Exist

  • Wednesday, November 04, 2009 10:31 PMchetjan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Thursday, November 05, 2009 12:36 AMAn Anon Coward Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Wednesday, November 04, 2009 11:38 PMAn Anon Coward Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    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
    •  
  • Wednesday, November 04, 2009 11:51 PMchetjan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Do I need any headers for that? And how do I call it after I have found it the window exists?
  • Thursday, November 05, 2009 12:36 AMAn Anon Coward Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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
    •  
  • Thursday, November 05, 2009 2:58 AMBrian MuthMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Saturday, November 07, 2009 5:15 PMchetjan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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)?
  • Saturday, November 07, 2009 7:33 PMBrian MuthMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Which email client are you talking about? Is it not configurable?
  • Saturday, November 07, 2009 9:20 PMchetjan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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?
  • Sunday, November 08, 2009 12:14 AMBrian MuthMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.

  • Sunday, November 08, 2009 1:27 AMchetjan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks so much.