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

标签 windows-desktop-gadgets

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

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

最佳答案

多年以来,我一直没有使用Visual Studio来处理小工具。没有它,您可以通过几种方法来调试小工具,只是没有那么广泛。例如,没有适当的调试器附加到进程中,就不能使用debugger;命令。您可以使用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() 方法确实可以提供帮助。

除了window.prompt,您还可以使用VBScript MsgBox() 函数:
window.execScript( //- Add MsgBox functionality for displaying error messages
      'Function vbsMsgBox (prompt, buttons, title)\r\n'
    + ' vbsMsgBox = MsgBox(prompt, buttons, 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, 16, "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!

关于windows-desktop-gadgets - 在没有Visual Studio的情况下调试Windows边栏小工具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2284101/

相关文章:

windows-desktop-gadgets - Windows 边栏小工具重新加载

javascript - Windows 7 使用什么来呈现桌面小工具,为什么我会使用 "g:"标签?

javascript - 查找 %LocalAppData% 路径并使用 JavaScript 添加新文件夹

security - "gadget vulnerability"是什么?

memory-leaks - 如何识别、修复、关闭Windows Sidebar小工具中的内存泄漏?

c# - Windows 7 边栏小工具

javascript - 从 Windows 桌面小工具登录网站

html - 小工具文件中的 CSS 样式和转换

c# - 使用 C# 在任务栏中时钟小工具

javascript - 从 SOAP 信封获取数据