As you know some application windows are not consistent which makes accessing them difficult. I have a script in popmenu.mnw which I've revised several times because code which I created using RoboScripter which initially worked fine stops working. The last time this happened I revised the RoboScripter code to cover every contingency, and obsessive person that I am, I wrote a script to convert the RoboScripter output into a cover all your bases script.
Lns = strreplace(clipget(), @crlf, @lf)
New = `boxopen('RoboScripter', 'Getting window informatiom.')`:@lf
LastWinCnt = 1
Cnts = itemcount(Lns, @lf)
for Cnt = 1 to Cnts
Ln = itemextract(Cnt, Lns, @lf)
Chk1 = strindexwild(Ln, 'window?=', 1)
Chk2 = strindexwild(Ln, 'ControlHandle=', 1)
Chk3 = strindex(Ln, 'result=', 0, @fwdscan)
if !Chk1 && !Chk2 && !Chk3
New = iteminsert(Ln, -1, New, @lf)
continue
endif
if Chk1
if strindex(Ln, 'window', 0, @fwdscan)==1
WinCnt = strsub(Ln, 7, 1)
else
if strindex(Ln, '; or ', 0, @fwdscan) then Ln = strreplace(Ln, '; or ', '')
else Ln = strsub(Ln, 3, -1)
Ln = 'if window':WinCnt:'==0 then ':Ln
endif
if WinCnt!=LastWinCnt
ChkLns = `if window`:LastWinCnt:`==0`:@lf
ChkLns = ChkLns:` display(3, 'window`:LastWinCnt:`', 'Cannot get handle!')`:@lf
ChkLns = ChkLns: ` return`:@lf
ChkLns = ChkLns:`endif`:@lf
ChkLns = ChkLns:`boxtext('window`:LastWinCnt:` = ':window`:LastWinCnt:`)`:@lf
New = New:@lf:ChkLns
LastWinCnt = WinCnt
endif
endif
if Chk2
if Chk2!=1
Ln = strreplace(Ln, '; or ', '')
Ln = 'if ControlHandle==0 then ':Ln
endif
endif
if Chk3
ChkLns = `if ControlHandle==0`:@lf
ChkLns = ChkLns:` display(3, 'ControlHandle', 'Cannot get handle!')`:@lf
ChkLns = ChkLns: ` return`:@lf
ChkLns = ChkLns:`endif`:@lf
ChkLns = ChkLns:`boxtext('ControlHandle = ':ControlHandle)`:@lf
New = New:@lf:ChkLns
break
endif
New = iteminsert(Ln, -1, New, @lf)
next ;Cnt
New = New:@lf:Ln
Ln = itemextract(Cnt+1, Lns, @lf)
New = New:@lf:Ln:@lf
New = strreplace(New, 'Message(', 'Pause(')
New = strreplace(New, @lf, @crlf)
clipput(New)
display(3, 'All Done!', 'Extended verbose lines are on the clipboard.')
Maybe you would consider revising RoboScripter's verbose output to something similar and save others the pain of trying to figure out while their perfectly adequate script all of a sudden stopped working. The BoxOpen and BoxText lines are not needed but let the user know the script is executing normally. Here's what the extended output looks like in code.
boxopen('RoboScripter', 'Getting window informatiom.')
;RoboScripter
; Made with
; RoboScripter ver: 45
; CtlMgr ver: 44039
AddExtender("wwctl44i.dll")
;Title: <untitled>
;ID: 110
;Class: SysListView32
;Level: 7
; Default cWndByWndSpec seems OK here
window1=cWndByWndSpec("wxWindowClassNR","Wrye Bash",2,-205,-214)
if window1==0 then window1=cWndByWndSpecName("Wrye Bash 298(Standalone), CBash v0.6.0: Default [SI]","Wrye Bash",2,-205,-214)
if window1==0 then window1=DllHwnd('Wrye Bash 298(Standalone), CBash v0.6.0: Default [SI]')
if window1==0
display(3, 'window1', 'Cannot get handle!')
return
endif
boxtext('window1 = ':window1)
window2=cWndByID(window1,-214)
if window2==0 then window2=cWndByClass(window1,`_wx_SysTabCtl32`)
if window2==0 then window2=cWndBySeq(window1,2)
if window2==0
display(3, 'window2', 'Cannot get handle!')
return
endif
boxtext('window2 = ':window2)
window3=cWndByID(window2,-243)
if window3==0 then window3=cWndBySeq(window2,2)
if window3==0
display(3, 'window3', 'Cannot get handle!')
return
endif
boxtext('window3 = ':window3)
window4=cWndByID(window3,-244)
if window4==0 then window4=cWndByName(window3,`splitter~`)
if window4==0 then window4=cWndByClass(window3,`wxWindowClass`)
if window4==0 then window4=cWndBySeq(window3,1)
if window4==0
display(3, 'window4', 'Cannot get handle!')
return
endif
boxtext('window4 = ':window4)
window5=cWndByID(window4,-245)
if window5==0 then window5=cWndBySeq(window4,1)
if window5==0
display(3, 'window5', 'Cannot get handle!')
return
endif
boxtext('window5 = ':window5)
window6=cWndByID(window5,-247)
if window6==0 then window6=cWndByName(window5,`panel~`)
if window6==0 then window6=cWndByClass(window5,`wxWindowClassNR`)
if window6==0 then window6=cWndBySeq(window5,1)
ControlHandle=cWndByID(window6,110)
if ControlHandle==0 then ControlHandle=cWndByClass(window6,`SysListView32`)
if ControlHandle==0 then ControlHandle=cWndBySeq(window6,1)
if ControlHandle==0
display(3, 'ControlHandle', 'Cannot get handle!')
return
endif
boxtext('ControlHandle = ':ControlHandle)
result=cGetLVColText(ControlHandle,6) ;Get a column of SysListView32 text
Pause("LV Col Text for col 6",StrReplace(result,@tab,@crlf)) ;TODO - Remove Message. Add code
We really appreciate the input. I can definitely see the value in adding some of the default error handling to the RoboScripter output.