I am looking for ideas on how I can programmatically determine which Window in my app is the active window when more than one is open.
As well, need ideas on how to determine from which window another window is opened from.
Currently I have a public variable (Property) called “VisibleWindow” that I populate with a given Window’s name when it gets the focus. I also have a variable (Property) in each Window called OpenArgs. This is programmatically populated by the calling window’s name. I then refer to VisibleWindow and OpenArgs when doing other things such as when a window closes.
This all seems to work but I’m thinking there must be a more efficient and perhaps “built-in” way to do this.
Each window has a timer with code to catch the Control Key combinations ie, CtrlP, CtrlA, CtrlR, etc.
The code needs to know which window is the active one otherwise CtrlP used on wTwo could actually run the code on wOne’s window.
As I said above, I would assign the window’s name (or something) to a Public property called VisibleWindow when a window gets opened. The code in the Timer of each window starts off with <If VisibleWindow=“windowname” then … this code can run. Windowname would be ie, wOne, wTwo, etc.
When I close a window, I then have to assign whatever window is then active to VisibleWindow. Additional code is required to specify to a windows OpenArgs property as to which window called it.
For example, wOne can be opened from Main.
wTwo can be opened from wOne and Main
wThree can be opened from wOne or wTwo.
When closing any of those windows, I use OpenArgs to determine what to populate VisibleWindow with.
Example, in the Close event of wTwo
If OpenArgs=wOne then
VisibleWindow=wOne
wTwo.Close
wOne.Show
End If
I am just looking for a slicker way to do this and reduce coding if possible.
RE: your timer code, you can simply ask, “am I the active window” and skip the code if you’re not.
If self = window(0) then
// I'm the active window
process keystokes
end
The above assumes the timer is embedded in the window and the code is in the timer’s Action event in the window. If the code is in a timer subclass, the test would be something like
[quote=46441:@Tim Hare]RE: your timer code, you can simply ask, “am I the active window” and skip the code if you’re not.
If self = window(0) then
// I'm the active window
process keystokes
end
The above assumes the timer is embedded in the window and the code is in the timer’s Action event in the window. If the code is in a timer subclass, the test would be something like
if me.window = window(0) then
[/quote]
Thanks Tim, I’ll give that a try. Now just need to simplify the “OpenArgs” thing.
Is there a way to determine which window is the active window in code in a Module?
Example, if I create a Method in a module (which would be publicly visible/accessible), how might I code it to determine which window is active on the screen if more than one window is open or visible?
You can test the Window.Title property of window(0) if each window has a different title. If they are all called the same thing then I’m not sure how it could be done. Maybe add a unique name property to each window and test window(0).name in the module’s method?
Right, you will need to create a property in each window called name, then test it against the values available to determine which window you re dealing with. Hope that makes sense?
Ok so I think I just realized the problem. The windows will have to be a subclass of Window for a method like that to work. That will complicate things so my solution is probably not the best. In the app I was thinking of, I used a subclass of window so this was relatively easy for me to implement. If the Windows are not subclasses you will probably need someone else to help you with a different method of doing this.