-
Notifications
You must be signed in to change notification settings - Fork 0
/
TaskBarIcon.cpp
158 lines (132 loc) · 4.17 KB
/
TaskBarIcon.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/msw/registry.h"
#include "wx/stdpaths.h"
#include "TaskBarIcon.h"
#include "DShowUtils.h"
enum
{
PU_AUTORUN = 10001,
PU_EXIT,
PU_DEVICES,
};
//max listed capture devices
const int PU_DEVICES_MAX = 20;
//registry key path our software
const char* REG_KEY_SOFTWARE_CAPTUREDEVICE_PROPERTIES = "SOFTWARE\\CaptureDeviceTaskbar\\Properties";
//Windows autorun key
const char* REG_KEY_SOFTWARE_WINDOWS_AUTORUN = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
const char* REG_KEY_SOFTWARE_WINDOWS_AUTORUN_CAPTUREDEVICE = "CaptureDeviceTaskbar";
wxBEGIN_EVENT_TABLE(MyTaskBarIcon, wxTaskBarIcon)
EVT_MENU(PU_AUTORUN, MyTaskBarIcon::OnMenuAutoRun)
EVT_MENU(PU_EXIT, MyTaskBarIcon::OnMenuExit)
EVT_TASKBAR_LEFT_DCLICK(MyTaskBarIcon::OnLeftButtonDClick)
EVT_MENU_RANGE(PU_DEVICES, PU_DEVICES + PU_DEVICES_MAX, MyTaskBarIcon::OnMenuDevice)
wxEND_EVENT_TABLE()
//constructor
MyTaskBarIcon::MyTaskBarIcon(wxApp* pParent)
: m_parent(pParent)
{
//read from registry
ReadDefaultDevice();
}
//close app
void MyTaskBarIcon::OnMenuAutoRun(wxCommandEvent&)
{
SetAutoRun(!IsAutoRun());
}
//close app
void MyTaskBarIcon::OnMenuExit(wxCommandEvent&)
{
m_parent->Exit();
}
//show property dialog for selected device
void MyTaskBarIcon::ShowDevicePropertiesDialog()
{
ShowDevicePropertyDialog(m_defaultDeviceName);
}
//show property dialog for a specific device, also update default device
void MyTaskBarIcon::ShowDevicePropertiesDialog(int id)
{
if (m_deviceNames.Count() > id)
{
m_defaultDeviceName = m_deviceNames[id];
WriteDefaultDevice();
ShowDevicePropertiesDialog();
}
}
//when user clicks on a specific device from the popup menu
void MyTaskBarIcon::OnMenuDevice(wxCommandEvent& event)
{
ShowDevicePropertiesDialog(event.GetId() - PU_DEVICES);
}
//interogate the devices and populate the popup menu
wxMenu* MyTaskBarIcon::CreatePopupMenu()
{
GetDevicesFriendlyName(m_deviceNames);
wxMenu* menu = new wxMenu();
if (m_deviceNames.IsEmpty())
{
wxMenuItem *item = new wxMenuItem(menu, PU_DEVICES, wxT("No capture devices found"));
item->Enable(false);
menu->Append(item);
}
else
{
//minimum between device count and max devices to show
int count = m_deviceNames.Count() < PU_DEVICES_MAX ? m_deviceNames.Count() : PU_DEVICES_MAX;
for (int i = 0; i < count; i++)
{
menu->Append(new wxMenuItem(menu, PU_DEVICES + i, m_deviceNames[i], wxEmptyString, wxITEM_CHECK))->Check(m_deviceNames[i] == m_defaultDeviceName);
}
}
menu->AppendSeparator();
menu->Append(new wxMenuItem(menu, PU_AUTORUN, "&Auto start", wxEmptyString, wxITEM_CHECK))->Check(IsAutoRun());
menu->AppendSeparator();
menu->Append(PU_EXIT, "E&xit");
return menu;
}
//quick-open the property dialog for the default device
void MyTaskBarIcon::OnLeftButtonDClick(wxTaskBarIconEvent&)
{
if(!m_defaultDeviceName.IsEmpty())
ShowDevicePropertiesDialog();
}
//read from registry the default device
void MyTaskBarIcon::ReadDefaultDevice()
{
wxRegKey key(wxRegKey::HKCU, REG_KEY_SOFTWARE_CAPTUREDEVICE_PROPERTIES);
if (key.Exists())
{
m_defaultDeviceName = key.QueryDefaultValue();
}
}
//write to registry the default device
void MyTaskBarIcon::WriteDefaultDevice()
{
wxRegKey key(wxRegKey::HKCU, REG_KEY_SOFTWARE_CAPTUREDEVICE_PROPERTIES);
key.Create();
key.SetValue("", m_defaultDeviceName);
}
bool MyTaskBarIcon::IsAutoRun()
{
wxRegKey key(wxRegKey::HKCU, REG_KEY_SOFTWARE_WINDOWS_AUTORUN);
key.Create();
return key.HasValue(REG_KEY_SOFTWARE_WINDOWS_AUTORUN_CAPTUREDEVICE);
}
void MyTaskBarIcon::SetAutoRun(bool autoRun)
{
wxRegKey key(wxRegKey::HKCU, REG_KEY_SOFTWARE_WINDOWS_AUTORUN);
if (autoRun)
{
key.Create();
wxString path = "\"" + wxStandardPaths::Get().GetExecutablePath() + "\"";
key.SetValue(REG_KEY_SOFTWARE_WINDOWS_AUTORUN_CAPTUREDEVICE, path);
}
else
{
key.DeleteValue(REG_KEY_SOFTWARE_WINDOWS_AUTORUN_CAPTUREDEVICE);
}
}