-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskbarNotificationAreaIcon.h
70 lines (64 loc) · 3.63 KB
/
TaskbarNotificationAreaIcon.h
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
#ifndef TASKBARNOTIFICATIONAREAICON_H
#define TASKBARNOTIFICATIONAREAICON_H
#include <memory>
#include <functional>
#include <windows.h>
//This is singleton class
//Why not use ordinary class or maybe simple (namespaced) include?
//We are keeping this thing as a class because it represents not a collection of functions but a complete object that provides taskbar icon functionality
//Not using singleton means supporting several instances of one class - and each instance will represent different window
//But because of static WNDPROC callback, static hwnd-to-object map variable should be used to keep track for which object WNDPROC is called
//So we are using singleton just to keep things simple and omit this mapping
class TskbrNtfAreaIcon {
public:
typedef std::function<bool(TskbrNtfAreaIcon* sender, WPARAM wParam, LPARAM lParam)> WmCommandFn;
typedef std::function<void(TskbrNtfAreaIcon* sender)> WmCloseFn;
typedef std::function<void(TskbrNtfAreaIcon* sender, bool critical)> WmEndsessionTrueFn;
private:
static std::unique_ptr<TskbrNtfAreaIcon> instance;
static UINT WmTaskbarCreated;
static WmCommandFn OnWmCommand; //WM_COMMAND msg is passed to OnWmCommand - it should return true if msg is fully processed or false if msg should be processed by DefWindowProc
static WmCloseFn OnWmClose; //WM_CLOSE msg (omitting params) is passed to OnWmClose
static WmEndsessionTrueFn OnWmEndsessionTrue; //WM_ENDSESSION w/ wParam=TRUE msg (omitting params, but w/ critical flag) is passed to OnWmEndsessionTrue
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
bool valid;
bool enabled;
HWND modal_wnd;
HINSTANCE app_instance;
HMENU icon_menu;
UINT default_menuid;
ATOM icon_atom;
NOTIFYICONDATA icon_ntfdata;
TskbrNtfAreaIcon(HINSTANCE hInstance, UINT icon_wm, const wchar_t* icon_tooltip, UINT icon_resid, const wchar_t* icon_class, UINT icon_menuid, UINT default_menuid);
void ShellNotifyIconModifyOrAdd();
public:
static TskbrNtfAreaIcon* MakeInstance(HINSTANCE hInstance, UINT icon_wm, const wchar_t* icon_tooltip, UINT icon_resid, const wchar_t* icon_class, UINT icon_menuid, UINT default_menuid, WmCommandFn OnWmCommand, WmCloseFn OnWmClose, WmEndsessionTrueFn OnWmEndsessionTrue);
bool IsValid() { return valid; }
void ChangeIconTooltip(const wchar_t* icon_tooltip);
void RefreshIcon();
void ChangeIcon(UINT icon_resid);
void Close();
void CloseAndQuit(int exit_code=0);
void Enable() { enabled=true; }
void Disable() { enabled=false; }
bool IsEnabled() { return enabled; }
void SetModalWnd(HWND hwnd) { modal_wnd=hwnd; }
HWND GetModalWnd() { return modal_wnd; }
HMENU GetIconMenu();
HWND GetIconWindow();
BOOL RemoveIconMenu(UINT uPosition, UINT uFlags);
BOOL ModifyIconMenu(UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCTSTR lpNewItem);
BOOL SetIconMenuItemInfo(UINT uItem, BOOL fByPosition, LPMENUITEMINFO lpmii);
BOOL EnableIconMenuItem(UINT uIDEnableItem, UINT uEnable);
DWORD CheckIconMenuItem(UINT uIDCheckItem, UINT uCheck);
BOOL CheckIconMenuRadioItem(UINT idFirst, UINT idLast, UINT idCheck, UINT uFlags);
UINT GetIconMenuState(UINT uId, UINT uFlags);
BOOL SetIconMenuInfo(LPCMENUINFO lpcmi);
BOOL GetIconMenuInfo(LPCMENUINFO lpcmi);
~TskbrNtfAreaIcon();
TskbrNtfAreaIcon(const TskbrNtfAreaIcon&)=delete; //Get rid of default copy constructor
TskbrNtfAreaIcon& operator=(const TskbrNtfAreaIcon&)=delete; //Get rid of default copy assignment operator
TskbrNtfAreaIcon(const TskbrNtfAreaIcon&&)=delete; //Get rid of default move constructor
TskbrNtfAreaIcon& operator=(const TskbrNtfAreaIcon&&)=delete; //Get rid of default move assignment operator
};
#endif //TASKBARNOTIFICATIONAREAICON_H