-
Notifications
You must be signed in to change notification settings - Fork 10
/
app.h
97 lines (82 loc) · 2.61 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "pinshape.h"
#include "trayicon.h"
#include "help.h"
class Options;
// Desktop Window Manager management.
// Dynamically loads dwmapi.dll and provides access to cached API state.
// The main window needs to call this to handle broadcast messages.
//
class Dwm : boost::noncopyable
{
typedef HRESULT (WINAPI* DwmIsCompositionEnabled_Ptr)(BOOL*);
public:
Dwm() {
dll = ef::Win::ModuleH::load(L"dwmapi");
if (dll) {
DwmIsCompositionEnabled_ = (DwmIsCompositionEnabled_Ptr)dll.getProcAddress("DwmIsCompositionEnabled");
}
wmDwmCompositionChanged();
}
bool isCompositionEnabled() const {
return cachedIsCompositionEnabled;
}
// WM_DWMCOMPOSITIONCHANGED handler
// TODO: use a msg filter instead of specific handler
void wmDwmCompositionChanged() {
BOOL b;
cachedIsCompositionEnabled = dll && SUCCEEDED(DwmIsCompositionEnabled_(&b)) && b;
}
private:
ef::Win::AutoModuleH dll;
DwmIsCompositionEnabled_Ptr DwmIsCompositionEnabled_;
bool cachedIsCompositionEnabled;
};
// Main application state.
// A single global instance is available to all translation units.
//
struct App : boost::noncopyable {
ef::Win::PrevInstance prevInst;
HWND mainWnd, aboutDlg, optionsDlg, layerWnd; //, activeModelessDlg;
HINSTANCE inst;
HMODULE resMod;
PinShape pinShape;
HICON smIcon, smClrIcon;
Help help;
int pinsUsed;
int optionPage;
TrayIcon trayIcon;
Dwm dwm;
static LPCWSTR APPNAME;
enum {
// app messages
WM_TRAYICON = WM_APP,
WM_PINSTATUS,
WM_PINREQ,
WM_QUEUEWINDOW,
WM_CMDLINE_OPTION, // for posting CMDLINE_* options in wparam
// pin wnd messages
WM_PIN_ASSIGNWND = WM_USER,
WM_PIN_RESETTIMER,
WM_PIN_GETPINNEDWND,
// system hotkey IDs
HOTID_ENTERPINMODE = 0,
HOTID_TOGGLEPIN = 1,
// app timers
TIMERID_AUTOPIN = 1,
};
App() : prevInst(L"EFDeskPinsRunning"),
mainWnd(0), aboutDlg(0), optionsDlg(0), layerWnd(0),
/*activeModelessDlg(0), */ inst(0), resMod(0),
smIcon(0), smClrIcon(0),
pinsUsed(0), optionPage(0), trayIcon(WM_TRAYICON, 0) {}
~App() { freeResMod(); DeleteObject(smIcon); DeleteObject(smClrIcon); }
bool loadResMod(const std::wstring& file, HWND msgParent);
void freeResMod();
bool initComctl();
bool chkPrevInst();
bool regWndCls();
bool createMainWnd(Options& opt);
void createSmClrIcon(COLORREF clr);
std::wstring trayIconTip();
};