Wpf应用程序隐藏在Windows启动时 [英] Wpf application hide on windows startup

查看:118
本文介绍了Wpf应用程序隐藏在Windows启动时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的应用程序正在Windows启动时启动。



必填:



我想要在Windows启动时隐藏应用程序,当我点击桌面快捷方式它应该启动。



我希望应用程序在Windows启动时的系统托盘中,当我点击桌面快捷方式或点击它应该启动的系统托盘图标。



我尝试过:



使用此代码,我可以在Windows启动时启动我的应用程序,但无法隐藏请帮助。



使用(RegistryKey key = Registry。 CurrentUser.OpenSubKey(SOFTWARE \\ Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ SetValue(myApplication,\+ System.Reflection.Assembly.GetExecutingAssembly()。Location +\);

}

解决方案
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


这篇关于Wpf应用程序隐藏在Windows启动时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆