0

I am creating a program that launches a command line utility to convert text to audio files (Balabolka commandline utility). One of the command line flags allows the program to display its conversion progress as a tooltip in the taskbar tray area.

I would like to intercept the tooltip text from the program so that I can display the progress of the conversion in a progress bar on my form, but I'm not sure how to grab that information. Here is the code that I am currently using the launch the application:

// Command line arguments for Balabolka
string arguments = "-f \"book.html\" -w \"book.wav\" -n \"Amy\" -tray";

// Set the working directory to the folder containing the Balabolka utility
Directory.SetCurrentDirectory("C:\\Balabolka");

// Launch the command line utility and serve other UI messages while waiting for it to close
using (Process balcon = Process.Start("balcon.exe", arguments))
{
    while (!balcon.HasExited)
    {
        Application.DoEvents();
        caption = balcon.MainWindowTitle; //<-- This doesn't get the info I want. It only returns "balabolka"
    }
}

The proper tooltip text reads something like, Balabolka [25%], and I can parse out the number if I can get at it.

I did come across this post earlier while searching: Get ToolTip Text from Icon in System Tray

But I'm wondering if there may be a simpler way to accomplish this since I'm the one starting the process in this case and have some information on it?

Jason O
  • 753
  • 9
  • 28
  • Sometimes things aren't easy. Process.Start gets you the [MainWIndowHandle](https://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle(v=vs.110).aspx) - which is where you're getting the text from - but not the systray handle, which you need to get what you want. PInvoke and `unsafe` code can seem (OK, is!) a bit scary, but it looks like the linked answer will work for you. – stuartd Aug 12 '18 at 22:41
  • Isn't this command line utility outputting anything in its `stdout` that you can read? Have you tried to? – Jimi Aug 12 '18 at 23:35
  • This is a simplified code example of the final program. Later, the utility will be used to pipe the raw PCM data output (through stdout) into LAME.exe to convert it to an mp3 file. So I don't believe I will get any useful information by directly monitoring stdout. – Jason O Aug 12 '18 at 23:57
  • So... I'm trying to basically get the code example from the link I posted to work (the one posted by user michalczerwinski. But I'm not sure what PInvokes he is using. I found a PInvoke.net plugin for Visual Studio, and also saw lots of libraries available through NuGet. Some of the parameters in the ones I found online aren't matching up with his code though... Can someone who has experience with this give me some pointers? I'm pulling my hair out trying to get the missing declares and enums needed to fully run the code sample... – Jason O Aug 14 '18 at 06:13

0 Answers0