diff --git a/KeyGo.sln b/KeyGo.sln index ddfbf34..0a040c0 100644 --- a/KeyGo.sln +++ b/KeyGo.sln @@ -8,13 +8,19 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {09416937-868E-4EE4-80EE-5E6FA81E2811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {09416937-868E-4EE4-80EE-5E6FA81E2811}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09416937-868E-4EE4-80EE-5E6FA81E2811}.Debug|x64.ActiveCfg = Debug|x64 + {09416937-868E-4EE4-80EE-5E6FA81E2811}.Debug|x64.Build.0 = Debug|x64 {09416937-868E-4EE4-80EE-5E6FA81E2811}.Release|Any CPU.ActiveCfg = Release|Any CPU {09416937-868E-4EE4-80EE-5E6FA81E2811}.Release|Any CPU.Build.0 = Release|Any CPU + {09416937-868E-4EE4-80EE-5E6FA81E2811}.Release|x64.ActiveCfg = Release|x64 + {09416937-868E-4EE4-80EE-5E6FA81E2811}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/KeyGo/AppControl.cs b/KeyGo/AppControl.cs index f91fa29..90fa6bd 100644 --- a/KeyGo/AppControl.cs +++ b/KeyGo/AppControl.cs @@ -40,7 +40,8 @@ namespace KeyGo { if (instance != null && instance.MainWindowHandle != IntPtr.Zero) { - ShowWindowAsync(instance.MainWindowHandle, (int)CmdShow.ShowNormal); + if (IsIconic(instance.MainWindowHandle)) + ShowWindowAsync(instance.MainWindowHandle, (int)CmdShow.Restore); SetForegroundWindow(instance.MainWindowHandle); } } @@ -138,7 +139,7 @@ namespace KeyGo /// the system restores it to its original size and position. /// An application should specify this flag when displaying the window for the first time. /// - ShowNormal= 1, + ShowNormal = 1, } [DllImport("User32.dll")] @@ -149,5 +150,11 @@ namespace KeyGo [DllImport("User32.dll")] private static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll")] + private static extern bool IsZoomed(IntPtr hWnd); + + [DllImport("user32.dll")] + private static extern bool IsIconic(IntPtr hWnd); } } \ No newline at end of file diff --git a/KeyGo/FormMain.Designer.cs b/KeyGo/FormMain.Designer.cs index dd2d8bd..5a7b62f 100644 --- a/KeyGo/FormMain.Designer.cs +++ b/KeyGo/FormMain.Designer.cs @@ -34,7 +34,12 @@ namespace KeyGo this.FLPHotKeys = new System.Windows.Forms.FlowLayoutPanel(); this.BtnAdd = new System.Windows.Forms.Button(); this.NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.TSMIExit = new System.Windows.Forms.ToolStripMenuItem(); + this.TSMIPowerOnStartup = new System.Windows.Forms.ToolStripMenuItem(); + this.TSMICloseToMin = new System.Windows.Forms.ToolStripMenuItem(); this.FLPHotKeys.SuspendLayout(); + this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // // FLPHotKeys @@ -62,10 +67,43 @@ namespace KeyGo // // NotifyIcon // + this.NotifyIcon.ContextMenuStrip = this.contextMenuStrip1; this.NotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("NotifyIcon.Icon"))); this.NotifyIcon.Visible = true; this.NotifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotifyIcon_MouseClick); // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.TSMICloseToMin, + this.TSMIPowerOnStartup, + this.TSMIExit}); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + this.contextMenuStrip1.Size = new System.Drawing.Size(149, 70); + // + // TSMIExit + // + this.TSMIExit.Name = "TSMIExit"; + this.TSMIExit.Size = new System.Drawing.Size(180, 22); + this.TSMIExit.Text = "退出"; + this.TSMIExit.Click += new System.EventHandler(this.TSMIExit_Click); + // + // TSMIPowerOnStartup + // + this.TSMIPowerOnStartup.CheckOnClick = true; + this.TSMIPowerOnStartup.Name = "TSMIPowerOnStartup"; + this.TSMIPowerOnStartup.Size = new System.Drawing.Size(180, 22); + this.TSMIPowerOnStartup.Text = "开机自启动"; + this.TSMIPowerOnStartup.CheckedChanged += new System.EventHandler(this.TSMIPowerOnStartup_CheckedChanged); + // + // TSMICloseToMin + // + this.TSMICloseToMin.CheckOnClick = true; + this.TSMICloseToMin.Name = "TSMICloseToMin"; + this.TSMICloseToMin.Size = new System.Drawing.Size(180, 22); + this.TSMICloseToMin.Text = "关闭为最小化"; + this.TSMICloseToMin.CheckedChanged += new System.EventHandler(this.TSMICloseToMin_CheckedChanged); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); @@ -81,9 +119,11 @@ namespace KeyGo this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "KeyGo!"; this.Deactivate += new System.EventHandler(this.FormMain_Deactivate); + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormMain_FormClosed); this.Load += new System.EventHandler(this.FormMain_Load); this.FLPHotKeys.ResumeLayout(false); + this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); } @@ -93,6 +133,10 @@ namespace KeyGo private System.Windows.Forms.FlowLayoutPanel FLPHotKeys; private System.Windows.Forms.Button BtnAdd; private System.Windows.Forms.NotifyIcon NotifyIcon; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; + private System.Windows.Forms.ToolStripMenuItem TSMIExit; + private System.Windows.Forms.ToolStripMenuItem TSMIPowerOnStartup; + private System.Windows.Forms.ToolStripMenuItem TSMICloseToMin; } } diff --git a/KeyGo/FormMain.cs b/KeyGo/FormMain.cs index ae9a1f4..9bdac8a 100644 --- a/KeyGo/FormMain.cs +++ b/KeyGo/FormMain.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Reflection; using System.Windows.Forms; namespace KeyGo @@ -13,6 +14,11 @@ namespace KeyGo public FormMain() { InitializeComponent(); + + Assembly assembly = Assembly.GetExecutingAssembly(); + AssemblyName thisAssemName = assembly.GetName(); + Text += $" - {thisAssemName.Version}"; + _KeyGo = LoadHotKeyItems(_DataFilePath); _KeyGo.FormHandle = Handle; var p = Process.GetCurrentProcess(); @@ -38,6 +44,16 @@ namespace KeyGo Console.WriteLine(_DataFilePath); } + bool isExit; + private void FormMain_FormClosing(object sender, FormClosingEventArgs e) + { + if (!isExit) + { + Hide(); + e.Cancel = true; + } + } + private void FormMain_FormClosed(object sender, FormClosedEventArgs e) { _KeyGo.UnRegAllKey(); @@ -148,7 +164,9 @@ namespace KeyGo private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) { - // 如果点击托盘图标 + // 鼠标左键点击托盘图标才触发 + if (e.Button != MouseButtons.Left) + return; // 当前在前台则隐藏 if (Visible) @@ -180,5 +198,21 @@ namespace KeyGo if (WindowState == FormWindowState.Minimized) Hide(); } + + private void TSMIExit_Click(object sender, EventArgs e) + { + isExit = true; + Close(); + } + + private void TSMIPowerOnStartup_CheckedChanged(object sender, EventArgs e) + { + MessageBox.Show("暂未完成", "TODO"); + } + + private void TSMICloseToMin_CheckedChanged(object sender, EventArgs e) + { + MessageBox.Show("暂未完成", "TODO"); + } } } \ No newline at end of file diff --git a/KeyGo/FormMain.resx b/KeyGo/FormMain.resx index 2358fcf..b8facb9 100644 --- a/KeyGo/FormMain.resx +++ b/KeyGo/FormMain.resx @@ -120,6 +120,9 @@ 17, 17 + + 130, 17 + diff --git a/KeyGo/KeyGo.cs b/KeyGo/KeyGo.cs index 7a37fb0..33b842f 100644 --- a/KeyGo/KeyGo.cs +++ b/KeyGo/KeyGo.cs @@ -193,13 +193,14 @@ namespace KeyGo { ++hotkey.TriggerCounter; + // 热键相应逻辑: // 若应用未启动:启动应用 // 若应用未在最前:激活窗体,推到最前 // 若应用已在最前:最小化窗体 var process = Process.GetProcessesByName(hotkey.ProcessName).Where(p => p.MainWindowHandle != IntPtr.Zero).ToArray().FirstOrDefault(); - if (process != null) + if (process != null ) { if (AppControl.IsForegroundWindow(process)) AppControl.MinimizeWindow(process); diff --git a/KeyGo/KeyGo.csproj b/KeyGo/KeyGo.csproj index 959cbcc..8369c6a 100644 --- a/KeyGo/KeyGo.csproj +++ b/KeyGo/KeyGo.csproj @@ -36,6 +36,25 @@ KeyGo.ico + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + diff --git a/KeyGo/Properties/AssemblyInfo.cs b/KeyGo/Properties/AssemblyInfo.cs index 009c528..3c9c7c1 100644 --- a/KeyGo/Properties/AssemblyInfo.cs +++ b/KeyGo/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.0.1")] [assembly: AssemblyFileVersion("1.0.0.0")]