常常使用系统 MsgBox 显示进行 Debug 工作,对于一些变量,尤其是对象的显示不太方便,于是做了这个小玩意
常常使用系统 MsgBox 显示进行 Debug 工作,对于一些变量,尤其是对象的显示不太方便,于是做了这个小玩意
使用示例:
sbox("a", [1,23,56,123])
效果:
源码:
#ErrorStdOut
;~ 文件名修改为 sBox.ahk 丢到 Autohotkey 用户库目录中,在任何脚本均可使用 sBox() 显示增强消息盒。
sBox(params*)
{
;~ strMsg := "显示内容:`n" . strMsg
for index, param in params
strMsg .= ( A_Index=1 ? "" : "`n`n`n" ) "***************************[第" A_Index "个参数]***************************`n`n" sBox_Obj(param)
;return SubStr(str, 1, -StrLen(sep))
if !WinExist("ahk_id " MRsuperMsgBoxHwnd)
biuldGuiMRsuperMsgBoxHwnd()
;~ gosub, biuldGuiMRsuperMsgBoxHwnd
GuiControl, MRsuperMsgBox:, MRsuperMsgBoxGuiTopStatus, 1
GuiControl, MRsuperMsgBox:, MRsuperMsgBoxHwndEdit, %strMsg%
Gui MRsuperMsgBox: Show, CEnter, 增强显示框
MRsuperMsgBoxGuiTop()
Pause, On
;~ return
}
biuldGuiMRsuperMsgBoxHwnd()
{
;~ biuldGuiMRsuperMsgBoxHwnd:
global
Gui MRsuperMsgBox: New, +HwndMRsuperMsgBoxHwnd,
Gui MRsuperMsgBox: +AlwaysOnTop
Gui MRsuperMsgBox: Font, S10, 微软雅黑
Gui MRsuperMsgBox: -MaximizeBox -MinimizeBox +MinSize +MinSize80x +MaxSize +MaxSize320x
Gui MRsuperMsgBox: Add, Text, , 显示内容:
Gui MRsuperMsgBox: Add, Checkbox, yp0 xp480 cGreen vMRsuperMsgBoxGuiTopStatus gMRsuperMsgBoxGuiTop -Wrap Checked1, 窗口置顶(&T)
Gui MRsuperMsgBox: Font, S10
Gui MRsuperMsgBox: Add, Edit, xs xm w640 R32 cBlue ReadOnly vMRsuperMsgBoxHwndEdit
Gui MRsuperMsgBox: Font, S12 W1000
Gui MRsuperMsgBox: Add, Text, cGreen gMRsuperMsgBoxGuiContinue vMRsuperMsgBoxGuiCloseVisual, 继续(&C)
Gui MRsuperMsgBox: Add, Text, yp0 xp100 cRed gMRsuperMsgBoxGuiExit, 退出(&X)
}
MRsuperMsgBoxGuiExit()
{
ExitApp
}
MRsuperMsgBoxGuiTop()
{
global
MRsuperMsgBoxGuiTopV := !(MRsuperMsgBoxGuiTopStatus:= !MRsuperMsgBoxGuiTopStatus) ? "-" : "+"
Gui MRsuperMsgBox: %MRsuperMsgBoxGuiTopV%AlwaysOnTop
Gui MRsuperMsgBox: Show
}
MRsuperMsgBoxGuiClose()
{
global
Gui MRsuperMsgBox: Hide
Pause, Off
}
MRsuperMsgBoxGuiCancel()
{
global
Gui MRsuperMsgBox: Hide
Pause, Off
}
MRsuperMsgBoxGuiContinue()
{
global
Gui MRsuperMsgBox: Hide
Pause, Off
}
sBox_Obj(obj="", lvl=0, now=0)
{
if !IsObject(obj)
return IsFunc(obj) ? "< 这是个函数!! >" : obj
now += 1
if lvl=now
return
str := now = 1 ? "++++++++++展开对象++++++++++" : str
objempty := 1
for i, v in obj
{
try
{
test := v
}
catch e
{
v := "[[!!错误!!]]"
}
objempty := 0
str := str "`n" sBox_objSym(now) sBox_objTree(now) "键名:< " i " > " ( v
? (IsObject(v)
? sBox_Obj(v, lvl, now) ;"`t" "第[" now+1 "]层对象" sBox_Obj(v, lvl, now)
;~ : ( IsFunc(v) ? "< 这是个函数!! >" : "键值:< " v " >") )
: "键值:< " v " >" )
: "")
}
if objempty
str := str "`n" sBox_objSym(now) sBox_objTree(now+1) "此对象未能取值"
str := str (now = 1 ? "`n++++++++++结束对象++++++++++" : "")
return str
}
sBox_objSym(str="", nums=6, symb=" ")
{
if IsObject(str)
str =
str := sBox_fillZeroNum(str, 4) ":"
loop % StrLen(str) < 6 ? nums - StrLen(str) : 1
str .= symb
return str
}
sBox_fillZeroNum(str="", zbit=4)
{
if IsObject(str)
str =
loop % StrLen(str)<=4 ? 4 - StrLen(str) : 0
str := "0" str
return str
}
sBox_objTree(lvl)
{
return lvl > 1 ? (sBox_objRptSym((lvl-1)*2)) "|-" : ""
}
sBox_objRptSym(rpt=1, sym=" ")
{
str := ""
loop % rpt
str .= sym
return str
}
;~ ExitApp
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
![[编程][小玩意][Func] sBox - 增强的显示盒子](https://www.autoahk.com/wp-content/uploads/2017/05/无标题-281x300.png)

