微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

windows-desktop-gadgets – 在没有Visual Studio的情况下调试Windows边栏小工具

我正在尝试在不使用Visual Studio的情况下创建侧边栏小工具.我一直在寻找调试它们的方法,但是一切都说Visual Studio JIT调试器是唯一的方法.

有没有人能够在没有Visual Studio的情况下调试侧边栏小工具?

多年来,我没有使用Visual Studio来处理小工具.有几种方法可以在没有它的情况下调试小工具,只是没有那么广泛.例如,您不能使用调试器;命令没有附加到进程的适当调试器.你可以做的是使用像 DebugView这样的程序来捕获 System.Debug.outputString()方法输出的消息:
function test ()
{
    System.Debug.outputString("Hello,I'm a debug message");
}

这允许您在代码的某些阶段输出变量转储和其他有用的信息,因此您可以随意跟踪它.

作为替代方法,您可以使用window.prompt()滚动自己的调试/脚本暂停消息.对于小工具已禁用alert()并且覆盖confirm()以始终返回true,但它们必须忽略prompt().

function test ()
{
     // execute some code

     window.prompt(someVarToOutput,JSON.stringify(someObjectToexamine));

     // execute some more code
}

如果要在代码执行期间检查对象的状态,JSON.stringify()方法确实有帮助.

您也可以使用VBScript MsgBox()函数代替window.prompt:

window.execScript( //- Add MsgBox functionality for displaying error messages
      'Function vbsMsgBox (prompt,buttons,title)\r\n'
    + ' vbsMsgBox = MsgBox(prompt,title)\r\n'
    + 'End Function',"vbscript"
);

vbsMsgBox("Some output message",16,"Your Gadget Name");

最后,您可以使用window.onerror事件处理程序捕获脚本中的所有错误.

function window.onerror (msg,file,line)
{
    // Using MsgBox
    var ErrorMsg = 'An error has occurred'+(line&&file?' in '+file+' on line '+line:'')+'.  The message returned was:\r\n\r\n'+ msg + '\r\n\r\nIf the error persists,please report it.';
    vbsMsgBox(ErrorMsg,"Your Gadget Name");

    // Using System.Debug.outputString
    System.Debug.outputString(line+": "+msg);

    // Using window.prompt
    window.prompt(file+": "+line,msg);        

    // Cancel the default action
    return true;
}

window.onerror事件甚至允许您输出发生错误的行号和文件(仅适用于IE8).

祝你好运调试,并且在发布你的小工具时记得不要离开任何window.prompts或MsgBoxes!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐