Link to home
Start Free TrialLog in
Avatar of tylermenezes
tylermenezes

asked on

How do I test if a window has focus (C#)?

I need to test if a Window has focus in C#. This window is an external application -- I am not looking to test if one of my forms is in focus. The only thing I know about the external application is it's process name (karafun.exe) and the title of the Window ("KaraFun").

Specifically, I'm looking to see when a karaoke song has ended, and the easiest way to do that is to see if the player control has focus. At this point I can load in a new song. So I guess what I need is code to: 1) Find the window by title (I used to know how to do this, but it's been a while) 2) Detect whether it has focus.

It would also be okay in this case to just get the title of the window with focus.
SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tylermenezes
tylermenezes

ASKER

Thanks to both of you. Neither solution completely addressed my problem (the former was more of a reference and the latter returned true for any window that process had open) but they both helped me solve the problem. Thanks.