Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Commit

Permalink
开机启动缩小至任务栏
Browse files Browse the repository at this point in the history
  • Loading branch information
Left024 committed Mar 30, 2021
1 parent f86185d commit 5f27c45
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 7 deletions.
Binary file modified .vs/NTU/v16/.suo
Binary file not shown.
17 changes: 14 additions & 3 deletions NTU/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ namespace NTU
public partial class Form1 : Form
{
BackgroundWorker bgworker = new BackgroundWorker();
public Form1()
String arg = null;
public Form1(String[] args)
{
if (args.Length > 0)
{
//获取启动时的命令行参数
arg = args[0];
}
InitializeComponent();

bgworker.WorkerReportsProgress = true;
Expand All @@ -49,7 +55,12 @@ public class CommonData

private void Form1_Load(object sender, EventArgs e)
{

if (arg != null)
{
//arg不为空,说明有启动参数,是从注册表启动的,则直接最小化到托盘
this.Visible = false;
this.ShowInTaskbar = false;
}
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);

Expand Down Expand Up @@ -250,7 +261,7 @@ private void startlogin_Click(object sender, EventArgs e)
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey run = key.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
run.SetValue("NTU", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
run.SetValue("NTU", System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + " -s");


}
Expand Down
5 changes: 3 additions & 2 deletions NTU/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ static class Program
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
static void Main(String[] args)
{
//https://blog.csdn.net/xggbest/article/details/104231935
//test
Process instance = RunningInstance();
if (instance != null) //进程中已经有一个实例在运行
{
HandleRunningInstance(instance);
MessageBox.Show("已经在运行!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else //没有实例在运行
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); //***主窗体的Form名称**//
Application.Run(new Form1(args)); //***主窗体的Form名称**//
}
}
#region 在进程中查找是否已经有实例在运行
Expand Down
2 changes: 1 addition & 1 deletion NTU/obj/Debug/NTU.application
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>qZnh5UQ1azLu9DXHcC+Flt2FRHlH9Qe821+b+kPzHug=</dsig:DigestValue>
<dsig:DigestValue>ajuWdjaknq11O/lprPvNfD2ZUrJi5zoH98rG+pB/D/0=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified NTU/obj/Debug/NTU.csprojAssemblyReference.cache
Binary file not shown.
Binary file modified NTU/obj/Debug/NTU.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion NTU/obj/Debug/NTU.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>ExTezM93/+nohdNnbYTAT+pH70E+HkXs2a/FJILw4k8=</dsig:DigestValue>
<dsig:DigestValue>eU1XyXMphUa3TXr44jinnY6dVSXLhW04rqaBfyYGhRQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified NTU/obj/Debug/NTU.pdb
Binary file not shown.

0 comments on commit 5f27c45

Please sign in to comment.