Real Software Forums
http://forums.realsoftware.com/

How to know what window is active
http://forums.realsoftware.com/viewtopic.php?f=10&t=47937
Page 1 of 1

Author:  MaxMBJ [ Tue May 21, 2013 11:55 am ]
Post subject:  How to know what window is active

I should know this but I don't: how can I tell which window is presently active (or perhaps better stated, has the focus)?

Author:  timhare [ Tue May 21, 2013 3:30 pm ]
Post subject:  Re: How to know what window is active

Window(0) is the topmost of your windows, and would be the one with focus if your app has focus. But it doesn't tell you which of the many apps running on the machine has focus. Finding that is platform specific and requires a different mechanism for each platform.

Author:  HMARROQUINC [ Tue May 21, 2013 6:44 pm ]
Post subject:  Re: How to know what window is active

I've handled this many different ways but a simple approach I've used is to have a global property that is updated each time a window gets focus, something like App.ActiveWindow and check against it when I need to find out which was the last window that got focus. Yup, not elegant but for simple stuff it works for me.

Author:  MaxMBJ [ Thu May 23, 2013 6:12 pm ]
Post subject:  Re: How to know what window is active

Thanks both of you.

I guess I'll choose the second route -- a global property. I thought there must be some property that says if a window is topmost and focused at any given time.

Thanks again.

Author:  timhare [ Thu May 23, 2013 6:19 pm ]
Post subject:  Re: How to know what window is active

Not to quibble, but the "last window that got focus" is already tracked for you by the system as Window(0). Neither approach tells you if that window actually has focus, though, or if some other app has focus. You didn't specify whether you cared one way or the other, but if you do need to know whether any window in your app actually has focus, you'll need to call some OS-specific methods, such as declares or applescript.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/