I’m having some trouble getting WindowsListMBS.WindowText to work in a DesktopWindows Thread on Windows 11. I haven’t tested Windows 10. The problem is that when I use WindowsListMBS.WindowText(i) in a Thread my code freezes. Just hangs with no error message. But the same code placed directly into a Windows Opening event works just fine.
I tried it from a fresh new Project to make sure something else in my code wasn’t causing the problem.
Here’s some code: I’ll include the whole test program. If you uncomment the line tTitle = w.WindowText(i), everything hangs
This code is for a custom windows taskbar. I’m using the WindowListMBS in a thread to keep track of my open windows.
#tag WindowCode
#tag Event
Sub Opening()
'Thread1.Start
Var w as new WindowsListMBS
Var tPID As Integer = 0
Var tClassN As String = ""
Var tTitle As String = ""
Var i As Integer = 0
Do Until i = w.WindowCount - 1
if w.WindowText(i).IndexOf("Xojo") > -1 Then
tPid = w.WindowProcessID(i)
tClassN = w.WindowClassName(i)
tTitle = w.WindowText(i)
End If
i = i + 1
Loop
label2.text = tPid.ToString + " | " + tClassN + " | " + tTitle + " | " + i.ToString
End Sub
#tag EndEvent
#tag EndWindowCode
#tag Events Thread1
#tag Event
Sub Run()
Var w as new WindowsListMBS
Var tPID As Integer = 0
Var tClassN As String = ""
Var tTitle As String = ""
Var i As Integer = 0
Do Until i = w.WindowCount - 1
tPid = w.WindowProcessID(i)
tClassN = w.WindowClassName(i)
'*** This is the problem code. Uncomment this and everything hangs ***
'tTitle = w.WindowText(i)
i = i + 1
Loop
me.AddUserInterfaceUpdate("tPid":tPid,"tClassN":tClassN,"tTitle":tTitle,"i":i) '
End Sub
#tag EndEvent
#tag Event
Sub UserInterfaceUpdate(data() as Dictionary)
For Each update As Dictionary In data
if update.Value("tTitle").StringValue.IndexOf("Xojo") > -1 Then
Label1.Text = update.Value("i").StringValue + " | " + update.Value("tPID").StringValue + " | " + update.Value("tClassN").StringValue + " | " + update.Value("tTitle").StringValue
End IF
Next
End Sub
#tag EndEvent
#tag EndEvents