Yes you can subclass a window, just insert a class and set its super to Window. There is no graphical interface designer for subclasses of windows created like this, however, so everything must be stored in window properties and created at runtime, as far as I know.
Not sure I would ever use a subclassed window, but I learned something.
You can subclass a window and give it logic (methods and properties). Then later, add a window to your project and set its Super to your window class, Lay it out as normal and use the logic baked into the window subclass.
[quote=46623:@Steve Albin]I knew I was missing something.
My code should be adjusted as so:
for i as integer = 0 to WindowCount - 1
if Window(i) isa wContacts then
if wContacts(window(i)).wName = "Contacts" then MsgBox "Found it"
end
next
[/quote]
All this does is tell me that a specific window is open ⊠it doesnât tell me which is the active one (the one that has focus) or which window was active when another window is opened.
Also, the statement < if wContacts(window(i)).wName = âContactsâ then MsgBox âFound itâ> serves no purpose because the statement < if Window(i) isa wContacts then> produces the same result (found it).
[quote=46730:@Rick Yerex]All this does is tell me that a specific window is open ⊠it doesnât tell me which is the active one (the one that has focus) or which window was active when another window is opened.
Also, the statement < if wContacts(window(i)).wName = âContactsâ then MsgBox âFound itâ> serves no purpose because the statement < if Window(i) isa wContacts then> produces the same result (found it).[/quote]
Window(0) is the front most window, so that is the one that is active or has focus. You wonât need a loop to find that.
If you know that you have only one instance of wContact, then yes you donât need to check the wName value. I thought you had multiple instances of the same type window and were using wName to differentiate them.
As for knowing which window was active when another one was opened, thatâs for you to implement in code. Xojo has nothing built in to tell you that as far as I know. You need to develop a scheme to track this.
ff
[quote=46735:@Steve Albin]
As for knowing which window was active when another one was opened, thatâs for you to implement in code. Xojo has nothing built in to tell you that as far as I know. You need to develop a scheme to track this.[/quote]
Steve, this is exactly why I came here and posed the question ⊠to get some help on developing some code to do this.
To that end; however, with some of the suggestions here, the documentation, and a little experimentation, I have figured out how to do what I need. I created a Method in a module called ShowActiveWindow which returns the active windowâs title.
Dim frontmostDocumentWindow As String
Dim lastOffset As Integer = WindowCount - 1
For i As Integer = 0 To lastOffset
Dim w As Window = Window(i)
If (w <> Nil) And (w.Frame = 0) And w.Visible Then
frontmostDocumentWindow = w.Title
Exit
End If
Next
Return frontmostDocumentWindow
Thanks for everyoneâs help in reaching my goal and expanding my knowledge.
Somewhere along the line, I must have gotten lost.
If you only want to know the front most (or âactiveâ) window, you only need to do this:
dim frontmostDocumentWindow as string
frontmostDocumentWindow = window(0).title
At one point, you indicated that you need to know other things in the window such as properties you added. Window(0) only knows how to access properties built in to the window class as it exists in the IDE. If you want to access properties you have added to the window, then you need to do something like your loop. Or cast the window(0) statement to your particular window.
The loop scheme you have is good when you need to find a window that is open, but you donât know if it is the active window.
Actually, the code you posted will NOT find the front most window. It will find the first document window that is visible.
The intent is not to find the frontmost document window per se` ⊠it is to find (or determine) which window IS the active one when I cause another window to open.
I tested this on 3 different windows and it does work.
On each window I have buttons that open each of the other windows.
I add the following code to each button on each window
dim TheWindow As String
TheWindow=ShowActiveWindow
Then I cause the appropriate window to open and populate itâs âOpenArgsâ Property with the variable . This method is telling me which window was active prior to the other window being opened⊠in other words, when a window gets opened, which window did it get opened from. This is exactly what I was looking for.
The use of added window Properties and accessing their contents was a result of other suggestions on how to do what I wanted to do ⊠not my choice or requirement even though I stated that ⊠sorry for misguiding anyone.
Nice⊠this also works.
Thanks!
geeesh⊠what a long way around to a simple result LOL