将文本信息传递到WPF“气球”窗口

时间:2010-01-15 17:37:40

标签: wpf window

我希望能够在我批量运行的命令行应用程序中发生错误时启动“气球”类型的窗口。我正在考虑创建一个WPF可执行文件,并将消息传递给它的命令行。

我可以在命令行中传递Unicode字符吗?

有人可以建议使用不同的方法将要显示的文本传递到外部可执行文件/ DLL中的WPF窗口吗?

[要求更多细节]

本质上我正在寻找一种简单的方法来启动带有一些消息的窗口,并且该消息将成为没有UI的可执行文件(Windows服务,ommand线工具)。我正在考虑在命令行上使用消息调用WPF应用程序,如下所示:
NotificationBalloon.exe“这是要显示的消息”
但那不支持unicode字符。我正在寻找一种更好的方法将邮件传递给NotificationBalloon.exe

3 个答案:

答案 0 :(得分:1)

您可以让NotificationBalloon.exe在执行时从标准输入中读取unicode字符串,并在生成时使用输入重定向:

public void Foo()
{
    SpawnBalloon("Whatever you want, this can be UNICODE as well.");
}

private void SpawnBalloon(string message)
{
    ProcessStartInfo psi = new ProcessStartInfo("NotificationBalloon.exe")
    {
        RedirectStandardInput = true
    };
    var process = Process.Start(psi);
    process.StandardInput.Write(message);
    process.StandardInput.Flush(); // Might not be necessary if AutoFlush is true
}

答案 1 :(得分:0)

不,你不能在命令行上传递unicode字符而不存在被破坏的风险。将它传递给包含文本的临时文件的路径(或者如果你想获得花哨,可以使用管道)

答案 2 :(得分:0)

我最终在命令行上传递UTF-16值并将其转换为main()函数内的字符串。例如:

NotifWindow.exe 00480065006c006c006f0021
将打印出“你好!”