mirror of
https://github.com/jie65535/KeyGo.git
synced 2025-06-02 17:39:13 +08:00
1. 增加 版本信息显示(在标题栏)
2. 增加 托盘右键菜单,在右键菜单中可退出应用 3. 修改 默认点击关闭按钮将缩小到托盘
This commit is contained in:
parent
24c36acfe8
commit
4193bbe512
@ -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
|
||||
|
@ -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.
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
44
KeyGo/FormMain.Designer.cs
generated
44
KeyGo/FormMain.Designer.cs
generated
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -120,6 +120,9 @@
|
||||
<metadata name="NotifyIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</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" />
|
||||
<data name="NotifyIcon.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
|
@ -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);
|
||||
|
@ -36,6 +36,25 @@
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>KeyGo.ico</ApplicationIcon>
|
||||
</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>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
@ -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")]
|
||||
|
Loading…
Reference in New Issue
Block a user