-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.cpp
64 lines (49 loc) · 1.56 KB
/
App.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
#include "wx/wxprec.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/taskbar.h"
#include "wx/msw/registry.h"
#include "App.h"
#include "TaskBarIcon.h"
wxIMPLEMENT_APP(MyApp);
//check the Windows Dark Mode setting
static bool locCheckDarkMode() {
#ifdef _WIN32
wxRegKey rk(wxRegKey::HKCU, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");
if (rk.Exists() && rk.HasValue("AppsUseLightTheme"))
{
long value = -1;
rk.QueryValue("AppsUseLightTheme", &value);
return value <= 0;
}
#endif
return wxSystemSettings::GetAppearance().IsDark();
}
//create the taskbar icon
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
if ( !wxTaskBarIcon::IsAvailable() )
{
wxMessageBox("There appears to be no system tray support in your current environment. This sample may not behave as expected.", "Warning", wxOK | wxICON_EXCLAMATION);
}
m_isDarkMode = locCheckDarkMode();
//needed to load the taskbar icon, as it's a PNG file
wxImage::AddHandler(new wxPNGHandler());
//create the taskbar icon object/logic
m_taskBarIcon = new MyTaskBarIcon(this);
//load the icon from resources, depending on the system theme
if(!m_taskBarIcon->SetIcon(wxBitmapBundle::FromResources((IsDarkMode())?"IDI_PNG2":"IDI_PNG1"), "Capture device properties\nRight click to show a list of devices"))
{
wxLogError("Could not set icon.");
}
return true;
}
//cleanup
int MyApp::OnExit()
{
delete m_taskBarIcon;
return wxApp::OnExit();
}