Suppose the control ID of a window to speak is 100, and that window is a child of the active window. Using the functions below, the text of the window could be spoken as follows:
Set oWindow = WindowFindControlID(ActiveWindow, 100) sText = WindowGetText(oWindow) Speak sText Function WindowFindControlID(oParent, iID) Dim oChildren, oChild Set WindowFindControlID = Nothing If TypeName(oParent) <> "Window" Then Exit Function Set oChildren = oParent.Children For Each oChild in oChildren If TypeName(oChild) = "Window" Then If oChild.IsValid And oChild.Control.ID = iID Then Set WindowFindControlID = oChild Exit Function End If End If Next Set oChildren = Nothing End Function Function WindowGetText(oWindow) Dim oText, oRectangle, oClips Dim sText WindowGetText = "" If TypeName(oWindow) <> "Window" Then Exit Function Set oText = Text Set oRectangle = oWindow.Rectangle.ScreenRectangle oText.EnclosingRectangle = oRectangle oText.Point = ScreenPoint(oRectangle.Left, oRectangle.Top) Do While True Set oClips = oText.NextLine If TypeName(oClips) <> "Clips" Then Exit Do If oClips.Count = 0 Then Exit Do If Len(sText) > 0 Then sText = sText & vbCrLf sText = sText & oClips.ClipsText Loop WindowGetText = sText End Function
