我正在开发一个小型发射器。它的主要思想是修复 Viber for Windows 中缺少的功能。我希望它使启动 Viber 最小化到仅托盘。通常,当 Viber 启动时,它会在桌面上显示一个 Viber 主窗口,并在系统托盘中显示一个图标。我一直都应该手动关闭这个过时的窗口。所以,我写了几行代码,但我发现它仍然无法关闭窗口:
using System;
using System.Diagnostics;
class ViberStrt {
static void Main() {
Process newProc = Process.Start("c:\\Users\\Dmytro\\AppData\\Local\\Viber\\Viber.exe");
Console.WriteLine("New process has started");
//newProc.CloseMainWindow();
newProc.WaitForExit();
newProc.Close();
newProc.Dispose();
Console.WriteLine("Process has finished");
//newProc.Kill();
}
}
但是无论我尝试了什么(关闭,处置) - 它都不起作用。方法 Kill 不适合,因为它会杀死所有人。但我唯一需要的是关闭 Viber 主窗口并将进程留在系统托盘中。
还有另一种方法:立即最小化启动 Viber:
using System;
using System.Diagnostics;
class LaunchViber
{
void OpenWithStartInfo()
{
ProcessStartInfo startInfo = new ProcessStartInfo("c:\\Users\\Dmytro\\AppData\\Local\\Viber\\Viber.exe");
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);
}
static void Main()
{
//Process newProc = Process.Start("c:\\Users\\Dmytro\\AppData\\Local\\Viber\\Viber.exe");
LaunchViber newProc = new LaunchViber();
newProc.OpenWithStartInfo();
}
}
在这种情况下,我们会在 TaskPane 上收到一个最小化窗口,在 SystemTray 中收到一个图标。但在这种情况下,我完全不知道如何摆脱 TaskPane 上的图标(如何关闭最小化窗口)。
我将感谢任何帮助/想法找到解决这个问题的方法。