开发者

Passing text info to a WPF "balloon" window

I want to be able to launch a "balloon"-type window when errors happen in my command line apps that I run in a batch. I'm thinking of creating a WPF executable, and passing it the message to be displayed on its command line.

Will I be able to pass in Unicode characters on its command line?

Can anyone suggest a different approach of passing the text to be displayed to a WPF window in an external executabl开发者_开发技巧e/DLL?

[request for more detail]

Essentially I'm looking for an easy way to launch a window with some message, and that message will come executables that don't have a UI (windows service, ommand line tool). I was thinking of calling a WPF app with the message on the command line, like this:

NotificationBalloon.exe "this is the message to display"

but that wouldn't support unicode characters. I'm looking for a better way to pass the message to NotificationBalloon.exe


You can have your NotificationBalloon.exe read the unicode string from standard input on execution, and use input redirection when spawning it:

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
}


No, you cannot pass unicode characters on the command line without the risk of them being mangled. Pass it a path to a temp file which contains the text (or if you want to get fancy, you could use pipes)


I ended up passing the UTF-16 values on the command line and converting it to a string inside my main() function. For example:

NotifWindow.exe 00480065006c006c006f0021
will print out "Hello!"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜