|
显示一个窗口的所有控件、子窗口及子窗口的控件、孙窗口
这是我刚学时写的一段代码,显示所有控件,比较方便的用于描述性编程,你看看是否有帮助:
testdebug1 是调用入口demo函数
'*printline 画表格的一行,notdata=true时画分隔行,notdata=false时画数据行
'strText是字符串,每隔用(%,)分开,如“abc%,def%,zzz”,必须大于16项数据
function printline(strText,notdata)
Dim list ,i,strLine,width,nLen,cols
cols=15
width=split("12,10,8,12,8,6,6,6,14,15,18,18,6,6,20,20,10",",",-1,1)'每列宽度
If notdata Then
strLine="+"
else
strLine="|"
list =split(strText,"%,",-1,1)
End If
For i=0 to cols
If notdata Then
strLine=strLine&string(0+width(i),"-")
else
nLen=0+width(i)-len(list(i))
If nLen>0 Then
strLine=strLine&string(nLen," ")&list(i)
else
strLine=strLine&left(list(i),width(i)-3)&"..."
End If
End If
If notdata Then
strLine=strLine&"+"
else
strLine=strLine&"|"
End If
Next
print strLine
'printline =strLine&chr(10)
End function
Sub testdebug1
Dim wndLogin
Set wndLogin=description.create()
wndLogin("regexpwndtitle").value="用户登录"
ListWindowProps wndLogin
End Sub
'ListWindowProps 函数用表格形式显示出一个窗口、对话框的所有控件的所有属性,如果有子窗口,也用递归方式显示另一个表格
'strDescript是一个对象,表示一个描述
Sub ListWindowProps(strDescript)
Dim strLoginDlgTitle ,ctlAlias,listchild(10),listCount
listCount=0
Set oDesc = Description.Create()
set children = window(strDescript).ChildObjects(oDesc)
print ""
print ""
print ""
printline "",true
printline "Class Name%,window id%,visible%,nativeclass%,height%,width%,abs_x%,abs_y%,object class%,regexpwndclass%,windowextendedstyle%,windowstyle%,x%,y%,regexpwndtitle%,attached text",false
printline "",True
printline window(strDescript).GetROProperty("Class Name")& "%,"&window(strDescript).GetROProperty("window id")&"%,"&window(strDescript).GetROProperty("visible")&"%,"&window(strDescript).GetROProperty("nativeclass")&"%,"&window(strDescript).GetROProperty("height")&"%,"&window(strDescript).GetROProperty("width")&"%,"&window(strDescript).GetROProperty("abs_x")&"%,"&window(strDescript).GetROProperty("abs_y")&"%,"&window(strDescript).GetROProperty("object class")&"%,"&window(strDescript).GetROProperty("regexpwndclass")&"%,"&window(strDescript).GetROProperty("windowextendedstyle")&"%,"&window(strDescript).GetROProperty("windowstyle")&"%,"&window(strDescript).GetROProperty("x")&"%,"&window(strDescript).GetROProperty("y")&"%,"&window(strDescript).GetROProperty("regexpwndtitle")&"%,"&"主/子窗口",false
printline "",true
For i=0 to children.count-1
printline children(i).GetROProperty("Class Name")& "%,"&children(i).GetROProperty("window id")&"%,"&children(i).GetROProperty("visible")&"%,"&children(i).GetROProperty("nativeclass")&"%,"&children(i).GetROProperty("height")&"%,"&children(i).GetROProperty("width")&"%,"&children(i).GetROProperty("abs_x")&"%,"&children(i).GetROProperty("abs_y")&"%,"&children(i).GetROProperty("object class")&"%,"&children(i).GetROProperty("regexpwndclass")&"%,"&children(i).GetROProperty("windowextendedstyle")&"%,"&children(i).GetROProperty("windowstyle")&"%,"&children(i).GetROProperty("x")&"%,"&children(i).GetROProperty("y")&"%,"&children(i).GetROProperty("regexpwndtitle")&"%,"&children(i).GetROProperty("attached text"),false
printline "",true
If (children(i).GetROProperty("Class Name")="Dialog" or children(i).GetROProperty("Class Name")="Window" ) and children(i).GetROProperty("visible") then
Set listchild(listCount) = Description.Create()
listchild(listCount)("Class Name").value=children(i).GetROProperty("Class Name")
listchild(listCount)("window id").value=children(i).GetROProperty("window id")
listchild(listCount)("height").value=children(i).GetROProperty("height")
listchild(listCount)("width").value=children(i).GetROProperty("width")
listchild(listCount)("x").value=children(i).GetROProperty("x")
listchild(listCount)("y").value=children(i).GetROProperty("y")
listCount=listCount+1
End If
Next
For i=0 to listCount-1
ListWindowProps listchild(i)
Next
End Sub |
|