-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray.cpp
More file actions
60 lines (46 loc) · 1.31 KB
/
tray.cpp
File metadata and controls
60 lines (46 loc) · 1.31 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
#include <windows.h>
#include "resource.h"
#include "tray.h"
namespace Tray
{
NOTIFYICONDATA nid;
void AddIcon(HWND h_wnd)
{
HICON h_icon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = h_wnd;
nid.uID = ICON_ID;
nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
nid.uCallbackMessage = WM_ICON;
nid.hIcon = h_icon;
Shell_NotifyIcon(NIM_ADD, &nid);
}
void RemoveIcon()
{
Shell_NotifyIcon(NIM_DELETE, &nid);
}
void ShowMenu(HWND hWnd)
{
POINT pt;
GetCursorPos(&pt);
// 创建弹出菜单
HMENU h_menu = CreatePopupMenu();
std::wstring current_exec_path;
#ifdef _DEBUG
AppendMenu(h_menu, MF_STRING, TRAY_MENU_TEST, L"调试");
#endif
// TODO: 暂时禁用设置菜单,没啥好用的
// AppendMenu(h_menu, MF_GRAYED, TRAY_MENU_SETTING, L"Setting");
AppendMenu(h_menu, MF_STRING, TRAY_MENU_EXIT, L"退出");
// 激活前台窗口
SetForegroundWindow(hWnd);
TrackPopupMenu(
h_menu,
TPM_BOTTOMALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON,
pt.x, pt.y,
0,
hWnd,
NULL);
DestroyMenu(h_menu);
}
};