Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kosaka-bun committed Apr 12, 2023
1 parent a72bd27 commit 0f35921
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 24 deletions.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# TrayIconRunner

可将任何桌面程序的主窗口最小化到托盘区域的工具
![DotNet](https://img.shields.io/badge/.Net-4.7.2-brightgreen?logo=dotnet)
[![License](https://img.shields.io/github/license/kosaka-bun/tray-icon-runner?label=License&color=blue&logo=GitHub)](./LICENSE)
![GitHub Stars](https://img.shields.io/github/stars/kosaka-bun/tray-icon-runner?label=Stars&logo=GitHub)
[![Release](https://img.shields.io/github/release/kosaka-bun/tray-icon-runner?label=Release&logo=GitHub)](../../releases)

## 简介
一款可将任何桌面程序的主窗口最小化到托盘区域的工具,其主要原理是先创建托盘图标,然后通过Win32 API来Hook一个进程的窗口事件,并在进程的主窗口被最小化时,隐藏主窗口。当托盘图标被点击时,再重新显示其窗口。

本项目采用GPL-3.0 License,其要求:

- 本项目的衍生项目需采用GPL-3.0 License。
- 必须在修改的文件中附有明确的说明,须包含所修改的部分及具体的修改日期。
- 通过任何形式发布衍生项目的可执行程序时,必须同时附带或公布衍生项目的源代码。

请参阅:[更新日志](./docs/changelog.md)

## 用法
以Elastic Search为例,Elastic Search是通过脚本启动的,启动后会持续保留一个控制台窗口,不便使用。

首先[下载](./releases/latest)TrayIconRunner的可执行程序,并将其解压到一个目录中。

在其启动脚本所在的目录,即`{安装目录}/bin`目录下,创建一个名为`startup.tir`的文件,在其中输入以下内容并保存。

```json
{
"file": "elasticsearch.bat",
"name": "Elastic Search"
}
```

右键`startup.tir`文件,设置其属性,将打开方式更改为TrayIconRunner。

![](./docs/img/1.png)

双击打开`startup.tir`,可以看到`elasticsearch.bat`已经被执行,且托盘区域已出现对应的图标。

![](./docs/img/2.png)

点击控制台窗口上的最小化按钮,可以看到控制台窗口已被隐藏,任务栏上已没有此控制台窗口的项目。

点击托盘区域的图标,可以看到控制台窗口已恢复显示。

停止Elastic Search的运行脚本,可以看到托盘区域的图标已消失,TrayIconRunner的进程也已结束。
1 change: 1 addition & 0 deletions TrayIconRunner.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ Global
{EBD717CD-0239-4A88-BBA1-0C6E176DDE8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBD717CD-0239-4A88-BBA1-0C6E176DDE8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBD717CD-0239-4A88-BBA1-0C6E176DDE8F}.Release|Any CPU.Build.0 = Release|Any CPU
{EBD717CD-0239-4A88-BBA1-0C6E176DDE8F}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
EndGlobal
28 changes: 5 additions & 23 deletions TrayIconRunner/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void launch() {
if(extName.ToLower().Equals(".exe")) {
initProcess(fileToOpen);
} else if(AssociatedPrograms.isDirectRunExtName(extName.ToLower())) {
initDirectRunProcess(fileToOpen);
initProcess(fileToOpen, directRun: true);
} else {
initProcess(exePath, fileToOpen);
}
Expand All @@ -114,13 +114,14 @@ public void launch() {
Application.Exit();
}

private void initProcess(string fileName, string arg = null) {
private void initProcess(string fileName, string arg = null,
bool directRun = false) {
process = new Process {
StartInfo = {
//设置要启动的应用程序
FileName = fileName,
//是否使用操作系统shell启动
UseShellExecute = false,
UseShellExecute = directRun,
//接受来自调用程序的输入信息
RedirectStandardInput = false,
//输出信息
Expand All @@ -131,29 +132,10 @@ private void initProcess(string fileName, string arg = null) {
CreateNoWindow = false
}
};
if(arg == null) return;
if(directRun || arg == null) return;
process.StartInfo.Arguments = arg.Contains("\"") ? arg : $"\"{arg}\"";
}

private void initDirectRunProcess(string fileName) {
process = new Process {
StartInfo = {
//设置要启动的应用程序
FileName = fileName,
//是否使用操作系统shell启动
UseShellExecute = true,
//接受来自调用程序的输入信息
RedirectStandardInput = false,
//输出信息
RedirectStandardOutput = false,
//输出错误
RedirectStandardError = false,
//不显示程序窗口
CreateNoWindow = false
}
};
}

private void hookMinimizeEvent(bool hookSubProcesses) {
//https://learn.microsoft.com/zh-cn/windows/win32/winauto/event-constants
const uint EVENT_TYPE_ID = 0x0016;
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 更新日志

## 1.0.0
初始版本。
Binary file added docs/img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0f35921

Please sign in to comment.