且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Wpf应用程序隐藏在Windows启动时

更新时间:2022-10-21 13:13:31

FORMA lly,这个问题毫无意义,因为在应用程序启动时你没有任何WPF应用程序。所以,没有什么可隐瞒的。如果你不想让它运行,不要启动它。



然而,从本质上讲,它具有完美的感觉。但是,首先,你不必隐藏任何东西。***的情况是,您可以创建一个Web应用程序,该应用程序在某些事件之前不会显示其UI(不会调用 Application.Run )。但是你关于点击桌面的第一个想法还不够好,所以如果你不介意的话,我不会讨论它。



你的第二个想法,关于系统托盘,要好得多。实际上,它非常好。如果它是 System.Windows.Forms.Application ,那很简单,因为这个库有类 System.Windows.Forms.NotifyIcon 用于此类目的。



对于WPF,请参阅:

WPF NotifyIcon扩展 [ ^ ],

https://www.nuget.org/packages/Hardcodet.NotifyIcon.Wpf [ ^ ]。



这个非常受欢迎的CodeProject文章也很有用: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon [ ^ ]。



-SA

Currently my application is getting launch on windows start up.

Required:

I want to HIDE the application on windows startup and when i click on desktop shortcut it should launch.
Or
I want the application to be in system tray on windows startup and when i click on desktop shortcut or click on system tray icon it should launch.

What I have tried:

Using this code i can able to launch my application on windows startup but cannot hide please help.

using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
key.SetValue("myApplication", "\"" + System.Reflection.Assembly.GetExecutingAssembly().Location + "\"");
}

Formally, the question makes no sense, because on application start you don't have any WPF applications. So, there is nothing to hide. If you don't want it to run, don't start it.

However, in essence, it has perfect sense. But, to start with, you don't have to hide anything. At best, you can create a Web application which does not show its UI (doesn't call Application.Run) until certain event. But your first idea, about clicking on the desktop, is not good enough, so I would not discuss it, if you don't mind.

Your second idea, about the system tray, is much better. Actually, it's quite good. If it was a System.Windows.Forms.Application, it would be simple, because this library has the class System.Windows.Forms.NotifyIcon for such purposes.

For WPF, please see:
WPF NotifyIcon extension[^],
https://www.nuget.org/packages/Hardcodet.NotifyIcon.Wpf[^].

This very popular CodeProject article can also be useful: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon[^].

—SA