1. 增加 版本信息显示(在标题栏)

2. 增加 托盘右键菜单,在右键菜单中可退出应用
3. 修改 默认点击关闭按钮将缩小到托盘
This commit is contained in:
筱傑 2021-04-28 22:17:00 +08:00
parent 24c36acfe8
commit 4193bbe512
8 changed files with 119 additions and 5 deletions

View File

@ -8,13 +8,19 @@ EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09416937-868E-4EE4-80EE-5E6FA81E2811}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {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|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.ActiveCfg = Release|Any CPU
{09416937-868E-4EE4-80EE-5E6FA81E2811}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -40,7 +40,8 @@ namespace KeyGo
{ {
if (instance != null && instance.MainWindowHandle != IntPtr.Zero) 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); SetForegroundWindow(instance.MainWindowHandle);
} }
} }
@ -138,7 +139,7 @@ namespace KeyGo
/// the system restores it to its original size and position. /// the system restores it to its original size and position.
/// An application should specify this flag when displaying the window for the first time. /// An application should specify this flag when displaying the window for the first time.
/// </summary> /// </summary>
ShowNormal= 1, ShowNormal = 1,
} }
[DllImport("User32.dll")] [DllImport("User32.dll")]
@ -149,5 +150,11 @@ namespace KeyGo
[DllImport("User32.dll")] [DllImport("User32.dll")]
private static extern IntPtr GetForegroundWindow(); 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);
} }
} }

View File

@ -34,7 +34,12 @@ namespace KeyGo
this.FLPHotKeys = new System.Windows.Forms.FlowLayoutPanel(); this.FLPHotKeys = new System.Windows.Forms.FlowLayoutPanel();
this.BtnAdd = new System.Windows.Forms.Button(); this.BtnAdd = new System.Windows.Forms.Button();
this.NotifyIcon = new System.Windows.Forms.NotifyIcon(this.components); 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.FLPHotKeys.SuspendLayout();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// FLPHotKeys // FLPHotKeys
@ -62,10 +67,43 @@ namespace KeyGo
// //
// NotifyIcon // NotifyIcon
// //
this.NotifyIcon.ContextMenuStrip = this.contextMenuStrip1;
this.NotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("NotifyIcon.Icon"))); this.NotifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("NotifyIcon.Icon")));
this.NotifyIcon.Visible = true; this.NotifyIcon.Visible = true;
this.NotifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(this.NotifyIcon_MouseClick); 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 // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
@ -81,9 +119,11 @@ namespace KeyGo
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "KeyGo!"; this.Text = "KeyGo!";
this.Deactivate += new System.EventHandler(this.FormMain_Deactivate); 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.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormMain_FormClosed);
this.Load += new System.EventHandler(this.FormMain_Load); this.Load += new System.EventHandler(this.FormMain_Load);
this.FLPHotKeys.ResumeLayout(false); this.FLPHotKeys.ResumeLayout(false);
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -93,6 +133,10 @@ namespace KeyGo
private System.Windows.Forms.FlowLayoutPanel FLPHotKeys; private System.Windows.Forms.FlowLayoutPanel FLPHotKeys;
private System.Windows.Forms.Button BtnAdd; private System.Windows.Forms.Button BtnAdd;
private System.Windows.Forms.NotifyIcon NotifyIcon; 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;
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection;
using System.Windows.Forms; using System.Windows.Forms;
namespace KeyGo namespace KeyGo
@ -13,6 +14,11 @@ namespace KeyGo
public FormMain() public FormMain()
{ {
InitializeComponent(); InitializeComponent();
Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyName thisAssemName = assembly.GetName();
Text += $" - {thisAssemName.Version}";
_KeyGo = LoadHotKeyItems(_DataFilePath); _KeyGo = LoadHotKeyItems(_DataFilePath);
_KeyGo.FormHandle = Handle; _KeyGo.FormHandle = Handle;
var p = Process.GetCurrentProcess(); var p = Process.GetCurrentProcess();
@ -38,6 +44,16 @@ namespace KeyGo
Console.WriteLine(_DataFilePath); 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) private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
{ {
_KeyGo.UnRegAllKey(); _KeyGo.UnRegAllKey();
@ -148,7 +164,9 @@ namespace KeyGo
private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) private void NotifyIcon_MouseClick(object sender, MouseEventArgs e)
{ {
// 如果点击托盘图标 // 鼠标左键点击托盘图标才触发
if (e.Button != MouseButtons.Left)
return;
// 当前在前台则隐藏 // 当前在前台则隐藏
if (Visible) if (Visible)
@ -180,5 +198,21 @@ namespace KeyGo
if (WindowState == FormWindowState.Minimized) if (WindowState == FormWindowState.Minimized)
Hide(); 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");
}
} }
} }

View File

@ -120,6 +120,9 @@
<metadata name="NotifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="NotifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value> <value>17, 17</value>
</metadata> </metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>130, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="NotifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="NotifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>

View File

@ -193,13 +193,14 @@ namespace KeyGo
{ {
++hotkey.TriggerCounter; ++hotkey.TriggerCounter;
// 热键相应逻辑: // 热键相应逻辑:
// 若应用未启动:启动应用 // 若应用未启动:启动应用
// 若应用未在最前:激活窗体,推到最前 // 若应用未在最前:激活窗体,推到最前
// 若应用已在最前:最小化窗体 // 若应用已在最前:最小化窗体
var process = Process.GetProcessesByName(hotkey.ProcessName).Where(p => p.MainWindowHandle != IntPtr.Zero).ToArray().FirstOrDefault(); var process = Process.GetProcessesByName(hotkey.ProcessName).Where(p => p.MainWindowHandle != IntPtr.Zero).ToArray().FirstOrDefault();
if (process != null) if (process != null )
{ {
if (AppControl.IsForegroundWindow(process)) if (AppControl.IsForegroundWindow(process))
AppControl.MinimizeWindow(process); AppControl.MinimizeWindow(process);

View File

@ -36,6 +36,25 @@
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>KeyGo.ico</ApplicationIcon> <ApplicationIcon>KeyGo.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />

View File

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]