-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (72 loc) · 2.77 KB
/
main.cpp
File metadata and controls
91 lines (72 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "tray_icon.h"
#include "consts.h"
#include "cmdline.h"
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) // 隐藏控制台界面 / hide console
using namespace std;
int main(int argc, char* argv[]) {
///// cmdline https://github.com/tanakh/cmdline
cmdline::parser psr;
psr.add<string>("icon", 'i', "list of trayIcons, separated by space", true, "");
psr.add<int>("delay", 'd', "start-up delay", false, 0);
psr.add<string>("action", 'a', "show or hide", false, "hide", cmdline::oneof<string>("show", "hide"));
psr.add("recoverable", 'r', "whether the icon can be restored to display");
psr.add<string>("help", 'h', specification, false, "");
psr.parse_check(argc, argv);
string iconStr = psr.get<string>("icon");
string action = psr.get<string>("action");
int delay = psr.get<int>("delay");
bool recoverable = psr.exist("recoverable");
printf("\naction:[%s]\ndelay:[%d]\nrecoverable:[%s]\nicons: [%s]\n", action.c_str(), delay, recoverable ? "true" : "false", iconStr.c_str());
if (iconStr == ""){
printf("\nerror: invalid argv --icon is empty");
return -1;
}
vector<string> sourceIcons = split(iconStr, ' ');
vector<string> icons;
for (int i = 0; i < sourceIcons.size(); i++)
{
string sourceIcon = sourceIcons.at(i);
string newIcon = sourceIcon;
trim(newIcon);
replaceAll(newIcon, "{dquotation}", "\"");
replaceAll(newIcon, "{squotation}", "'");
replaceAll(newIcon, "{space}", " ");
if (newIcon == "") continue;
icons.push_back(newIcon);
printf("\nicon:[%s]\tsource:[%s]", newIcon.c_str(), sourceIcon.c_str());
}
bool visible = action == "show";
printf("\ndelay %d seconds...", delay);
Sleep(delay * 1000);
printf("\nstart to execute...");
SetTrayIconVisable(FindOverflowTrayWindow(), ICON_AREA::AREA_OVERFLOW, icons, visible, !recoverable);
SetTrayIconVisable(FindNormalTrayWindow(), ICON_AREA::AREA_TASKBAR, icons, visible, !recoverable);
printf("\ndone.");
return 0;
}
/// ---for test---debug in vs---
//int main() {
// bool visible = false;
//
// vector<string> icons;
// string c1 = "Quick";
// string c2 = "Ditto";
// string c3 = "uTools.exe";
// string c4 = "Everything";
// string c5 = "NVIDIA";
// string c6 = "AMD";
// string c7 = "ShareOnLan";
// icons.push_back(c1);
// icons.push_back(c2);
// icons.push_back(c3);
// icons.push_back(c4);
// icons.push_back(c5);
// icons.push_back(c6);
// icons.push_back(c7);
//
// SetTrayIconVisable(FindOverflowTrayWindow(), ICON_AREA::AREA_OVERFLOW, icons, visible, true); // set isHardDelete to true if you don't want to restore the icon
// SetTrayIconVisable(FindNormalTrayWindow(), ICON_AREA::AREA_TASKBAR, icons, visible, true);
//
// fflush(stdout);
// system("pause");
//}