From 084f343b2757082150285c7744fe085a6b264af6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Steinh=C3=B6fer?= Date: Tue, 12 Apr 2022 11:36:20 +0200 Subject: [PATCH] New settings tab. --- WinMute/MuteControl.cpp | 7 +- WinMute/SettingsDlg.cpp | 17 ++- WinMute/Settings_GeneralDlg.cpp | 4 +- WinMute/Settings_MuteDlg.cpp | 119 ++++++++++++++++++++ WinMute/Settings_QuietHoursDlg.cpp | 38 +++---- WinMute/Utility.cpp | 3 +- WinMute/WMSettings.cpp | 54 +++++++-- WinMute/WMSettings.h | 5 +- WinMute/WinMute.cpp | 169 ++++++++++++++++++----------- WinMute/WinMute.h | 3 +- WinMute/WinMute.rc | 61 ++++++++--- WinMute/WinMute.vcxproj | 1 + WinMute/WinMute.vcxproj.filters | 3 + WinMute/resource.h | 15 ++- 14 files changed, 385 insertions(+), 114 deletions(-) create mode 100644 WinMute/Settings_MuteDlg.cpp diff --git a/WinMute/MuteControl.cpp b/WinMute/MuteControl.cpp index 3bc0bd8..489a694 100644 --- a/WinMute/MuteControl.cpp +++ b/WinMute/MuteControl.cpp @@ -47,8 +47,11 @@ enum MuteType { MuteTypeCount // Meta }; -MuteControl::MuteControl() - : trayIcon_(nullptr), notificationsEnabled_(false), displayWasOffOnce_(false) +MuteControl::MuteControl() : + restoreVolume_(false), + notificationsEnabled_(false), + displayWasOffOnce_(false), + trayIcon_(nullptr) { MuteConfig initMuteConf; initMuteConf.active = false; diff --git a/WinMute/SettingsDlg.cpp b/WinMute/SettingsDlg.cpp index 6ccd061..0d13d19 100644 --- a/WinMute/SettingsDlg.cpp +++ b/WinMute/SettingsDlg.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. enum SettingsTabsIDs { SETTINGS_TAB_GENERAL = 0, + SETTINGS_TAB_MUTE, SETTINGS_TAB_QUIETHOURS, SETTINGS_TAB_COUNT }; @@ -55,6 +56,7 @@ struct SettingsDlgData { extern INT_PTR CALLBACK Settings_QuietHoursDlgProc(HWND, UINT, WPARAM, LPARAM); extern INT_PTR CALLBACK Settings_GeneralDlgProc(HWND, UINT, WPARAM, LPARAM); +extern INT_PTR CALLBACK Settings_MuteDlgProc(HWND, UINT, WPARAM, LPARAM); static void InsertTabItem(HWND hTabCtrl, UINT id, const TCHAR* itemName) { @@ -101,6 +103,7 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar dlgData->hTabCtrl = GetDlgItem(hDlg, IDC_SETTINGS_TAB); InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_GENERAL, _T("General")); + InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_MUTE, _T("Mute")); InsertTabItem(dlgData->hTabCtrl, SETTINGS_TAB_QUIETHOURS, _T("Quiet Hours")); dlgData->hTabs[SETTINGS_TAB_GENERAL] = CreateDialogParam( @@ -109,6 +112,12 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar dlgData->hTabCtrl, Settings_GeneralDlgProc, reinterpret_cast(settings)); + dlgData->hTabs[SETTINGS_TAB_MUTE] = CreateDialogParam( + nullptr, + MAKEINTRESOURCE(IDD_SETTINGS_MUTE), + dlgData->hTabCtrl, + Settings_MuteDlgProc, + reinterpret_cast(settings)); dlgData->hTabs[SETTINGS_TAB_QUIETHOURS] = CreateDialogParam( nullptr, MAKEINTRESOURCE(IDD_SETTINGS_QUIETHOURS), @@ -135,10 +144,14 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar if (LOWORD(wParam) == IDOK) { for (int i = 0; i < SETTINGS_TAB_COUNT; ++i) { SendMessage(dlgData->hTabs[i], WM_SAVESETTINGS, 0, 0); + EndDialog(dlgData->hTabs[i], 0); } EndDialog(hDlg, 0); } else if (LOWORD(wParam) == IDCANCEL) { - EndDialog(hDlg, 0); + for (int i = 0; i < SETTINGS_TAB_COUNT; ++i) { + EndDialog(dlgData->hTabs[i], 0); + } + EndDialog(hDlg, 1); } return 0; case WM_NOTIFY: { @@ -153,7 +166,7 @@ INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lPar return 0; } case WM_CLOSE: - EndDialog(hDlg, 0); + EndDialog(hDlg, 1); return TRUE; case WM_DESTROY: delete dlgData; diff --git a/WinMute/Settings_GeneralDlg.cpp b/WinMute/Settings_GeneralDlg.cpp index 6822601..84c73ec 100644 --- a/WinMute/Settings_GeneralDlg.cpp +++ b/WinMute/Settings_GeneralDlg.cpp @@ -53,10 +53,10 @@ INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA DWORD enabled = settings->IsAutostartEnabled(); Button_SetCheck(hAutostart, enabled ? BST_CHECKED : BST_UNCHECKED); - enabled = !!settings->QueryValue(SettingsKey::NOTIFICATIONS_ENABLED, FALSE); + enabled = !!settings->QueryValue(SettingsKey::NOTIFICATIONS_ENABLED); Button_SetCheck(hNotify, enabled ? BST_CHECKED : BST_UNCHECKED); - enabled = !!settings->QueryValue(SettingsKey::LOGGING_ENABLED, FALSE); + enabled = !!settings->QueryValue(SettingsKey::LOGGING_ENABLED); Button_SetCheck(hLogging, enabled ? BST_CHECKED : BST_UNCHECKED); Button_Enable(hOpenLog, enabled); diff --git a/WinMute/Settings_MuteDlg.cpp b/WinMute/Settings_MuteDlg.cpp new file mode 100644 index 0000000..6b3734b --- /dev/null +++ b/WinMute/Settings_MuteDlg.cpp @@ -0,0 +1,119 @@ +/* + WinMute + Copyright (c) 2022, Alexander Steinhoefer + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the author nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + +#include "common.h" + +static void SetCheckButton(HWND hBtn, const WMSettings& settings, SettingsKey key) +{ + DWORD enabled = !!settings.QueryValue(key); + Button_SetCheck(hBtn, enabled ? BST_CHECKED : BST_UNCHECKED); +} + +static void SetOption(HWND hBtn, WMSettings& settings, SettingsKey key) +{ + int enable = Button_GetCheck(hBtn) == BST_CHECKED; + settings.SetValue(key, enable); +} + +INT_PTR CALLBACK Settings_MuteDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + UNREFERENCED_PARAMETER(wParam); + + switch (msg) { + case WM_INITDIALOG: + { + if (IsAppThemed()) { + EnableThemeDialogTexture(hDlg, ETDT_ENABLETAB); + } + + HWND hMuteOnLock = GetDlgItem(hDlg, IDC_MUTE_WHEN_WS_LOCKED); + HWND hMuteOnScreensaver = GetDlgItem(hDlg, IDC_MUTE_WHEN_SCREENSAVER_STARTS); + HWND hMuteOnScreenOff = GetDlgItem(hDlg, IDC_MUTE_WHEN_SCREEN_OFF); + HWND hMuteOnRDP = GetDlgItem(hDlg, IDC_MUTE_WHEN_RDP_SESSION); + HWND hRestoreVolume = GetDlgItem(hDlg, IDC_RESTOREVOLUME); + + HWND hMuteOnShutdown = GetDlgItem(hDlg, IDC_MUTE_WHEN_SHUTDOWN); + HWND hMuteOnSleep = GetDlgItem(hDlg, IDC_MUTE_WHEN_SLEEP); + HWND hMuteOnLogout = GetDlgItem(hDlg, IDC_MUTE_WHEN_LOGOUT); + + WMSettings* settings = reinterpret_cast(lParam); + assert(settings != NULL); + SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast(settings)); + + // With restore + SetCheckButton(hMuteOnLock, *settings, SettingsKey::MUTE_ON_LOCK); + SetCheckButton(hMuteOnScreensaver, *settings, SettingsKey::MUTE_ON_SCREENSAVER); + SetCheckButton(hMuteOnScreenOff, *settings, SettingsKey::MUTE_ON_DISPLAYSTANDBY); + SetCheckButton(hMuteOnRDP, *settings, SettingsKey::MUTE_ON_RDP); + SetCheckButton(hRestoreVolume, *settings, SettingsKey::RESTORE_AUDIO); + + // Without restore + SetCheckButton(hMuteOnShutdown, *settings, SettingsKey::MUTE_ON_SHUTDOWN); + SetCheckButton(hMuteOnSleep, *settings, SettingsKey::MUTE_ON_SUSPEND); + SetCheckButton(hMuteOnLogout, *settings, SettingsKey::MUTE_ON_LOGOUT); + + return TRUE; + } + case WM_SAVESETTINGS: + { + WMSettings* settings = reinterpret_cast(GetWindowLongPtr(hDlg, GWLP_USERDATA)); + + HWND hMuteOnLock = GetDlgItem(hDlg, IDC_MUTE_WHEN_WS_LOCKED); + HWND hMuteOnScreensaver = GetDlgItem(hDlg, IDC_MUTE_WHEN_SCREENSAVER_STARTS); + HWND hMuteOnScreenOff = GetDlgItem(hDlg, IDC_MUTE_WHEN_SCREEN_OFF); + HWND hMuteOnRDP = GetDlgItem(hDlg, IDC_MUTE_WHEN_RDP_SESSION); + HWND hRestoreVolume = GetDlgItem(hDlg, IDC_RESTOREVOLUME); + + HWND hMuteOnShutdown = GetDlgItem(hDlg, IDC_MUTE_WHEN_SHUTDOWN); + HWND hMuteOnSleep = GetDlgItem(hDlg, IDC_MUTE_WHEN_SLEEP); + HWND hMuteOnLogout = GetDlgItem(hDlg, IDC_MUTE_WHEN_LOGOUT); + + // With restore + SetOption(hMuteOnLock, *settings, SettingsKey::MUTE_ON_LOCK); + SetOption(hMuteOnScreensaver, *settings, SettingsKey::MUTE_ON_SCREENSAVER); + SetOption(hMuteOnScreenOff, *settings, SettingsKey::MUTE_ON_DISPLAYSTANDBY); + SetOption(hMuteOnRDP, *settings, SettingsKey::MUTE_ON_RDP); + SetOption(hRestoreVolume, *settings, SettingsKey::RESTORE_AUDIO); + + // Without restore + SetOption(hMuteOnShutdown, *settings, SettingsKey::MUTE_ON_SHUTDOWN); + SetOption(hMuteOnSleep, *settings, SettingsKey::MUTE_ON_SUSPEND); + SetOption(hMuteOnLogout, *settings, SettingsKey::MUTE_ON_LOGOUT); + + return 0; + } + default: + break; + } + return FALSE; +} diff --git a/WinMute/Settings_QuietHoursDlg.cpp b/WinMute/Settings_QuietHoursDlg.cpp index 4e789e7..c57cea8 100644 --- a/WinMute/Settings_QuietHoursDlg.cpp +++ b/WinMute/Settings_QuietHoursDlg.cpp @@ -73,11 +73,11 @@ static bool SaveQuietHours( int setStart = start->wHour * 3600 + start->wMinute * 60 + start->wSecond; int setEnd = end->wHour * 3600 + end->wMinute * 60 + end->wSecond; - if (!settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, enabled) || - !settings->SetValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, forceUnmute) || - !settings->SetValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, showNotifications) || - !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) || - !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { + if (!settings->SetValue(SettingsKey::QUIETHOURS_ENABLE, enabled) + || !settings->SetValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, forceUnmute) + || !settings->SetValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, showNotifications) + || !settings->SetValue(SettingsKey::QUIETHOURS_START, setStart) + || !settings->SetValue(SettingsKey::QUIETHOURS_END, setEnd)) { TaskDialog( nullptr, nullptr, @@ -113,13 +113,13 @@ INT_PTR CALLBACK Settings_QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, EnableThemeDialogTexture(hDlg, ETDT_ENABLETAB); } - DWORD qhEnabled = !!settings->QueryValue(SettingsKey::QUIETHOURS_ENABLE, FALSE); + DWORD qhEnabled = !!settings->QueryValue(SettingsKey::QUIETHOURS_ENABLE); Button_SetCheck(hEnable, qhEnabled ? BST_CHECKED : BST_UNCHECKED); - DWORD qhForceUnmute = !!settings->QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, FALSE); + DWORD qhForceUnmute = !!settings->QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE); Button_SetCheck(hForce, qhForceUnmute ? BST_CHECKED : BST_UNCHECKED); - DWORD qhNotifications = !!settings->QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, FALSE); + DWORD qhNotifications = !!settings->QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS); Button_SetCheck(hNotify, qhNotifications ? BST_CHECKED : BST_UNCHECKED); EnableWindow(hForce, qhEnabled); @@ -127,8 +127,8 @@ INT_PTR CALLBACK Settings_QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, EnableWindow(hStart, qhEnabled); EnableWindow(hEnd, qhEnabled); - int setStart = settings->QueryValue(SettingsKey::QUIETHOURS_START, 0); - int setEnd = settings->QueryValue(SettingsKey::QUIETHOURS_END, 0); + int setStart = settings->QueryValue(SettingsKey::QUIETHOURS_START); + int setEnd = settings->QueryValue(SettingsKey::QUIETHOURS_END); SYSTEMTIME start; GetLocalTime(&start); @@ -154,14 +154,14 @@ INT_PTR CALLBACK Settings_QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, { SYSTEMTIME start; SYSTEMTIME end; - HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); - HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); + HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); + HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); HWND hNotify = GetDlgItem(hDlg, IDC_SHOWNOTIFICATIONS); - HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); - HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); + HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); + HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); WMSettings* settings = reinterpret_cast(GetWindowLongPtr(hDlg, GWLP_USERDATA)); - int qhEnabled = Button_GetCheck(hEnable) == BST_CHECKED; - int qhForceUnmute = Button_GetCheck(hForce) == BST_CHECKED; + int qhEnabled = Button_GetCheck(hEnable) == BST_CHECKED; + int qhForceUnmute = Button_GetCheck(hForce) == BST_CHECKED; int qhNotifications = Button_GetCheck(hNotify) == BST_CHECKED; DateTime_GetSystemtime(hStart, &start); DateTime_GetSystemtime(hEnd, &end); @@ -175,10 +175,10 @@ INT_PTR CALLBACK Settings_QuietHoursDlgProc(HWND hDlg, UINT msg, WPARAM wParam, case WM_COMMAND: { HWND hEnable = GetDlgItem(hDlg, IDC_ENABLEQUIETHOURS); - HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); + HWND hForce = GetDlgItem(hDlg, IDC_FORCEUNMUTE); HWND hNotify = GetDlgItem(hDlg, IDC_SHOWNOTIFICATIONS); - HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); - HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); + HWND hStart = GetDlgItem(hDlg, IDC_QUIETHOURS_START); + HWND hEnd = GetDlgItem(hDlg, IDC_QUIETHOURS_END); if (LOWORD(wParam) == IDC_ENABLEQUIETHOURS) { int qhEnabled = Button_GetCheck(hEnable) == BST_CHECKED; EnableWindow(hStart, qhEnabled); diff --git a/WinMute/Utility.cpp b/WinMute/Utility.cpp index b8eeaa5..db61db2 100644 --- a/WinMute/Utility.cpp +++ b/WinMute/Utility.cpp @@ -61,7 +61,8 @@ void PrintWindowsError(LPCWSTR lpszFunction, DWORD lastError) lpszFunction, lastError, reinterpret_cast(lpMsgBuf)); - TaskDialog(nullptr, + TaskDialog( + nullptr, nullptr, PROGRAM_NAME, static_cast(lpDisplayBuf), diff --git a/WinMute/WMSettings.cpp b/WinMute/WMSettings.cpp index aa95722..742bca5 100644 --- a/WinMute/WMSettings.cpp +++ b/WinMute/WMSettings.cpp @@ -49,6 +49,9 @@ static LPCWSTR KeyToStr(SettingsKey key) case SettingsKey::MUTE_ON_DISPLAYSTANDBY: keyStr = _T("MuteOnDisplayStandby"); break; + case SettingsKey::MUTE_ON_RDP: + keyStr = _T("MuteOnRDP"); + break; case SettingsKey::RESTORE_AUDIO: keyStr = _T("RestoreAudio"); break; @@ -86,6 +89,43 @@ static LPCWSTR KeyToStr(SettingsKey key) return keyStr; } +static DWORD GetDefaultSetting(SettingsKey key) +{ + switch (key) { + case SettingsKey::MUTE_ON_LOCK: + return 1; + case SettingsKey::MUTE_ON_SCREENSAVER: + return 1; + case SettingsKey::MUTE_ON_DISPLAYSTANDBY: + return 1; + case SettingsKey::MUTE_ON_RDP: + return 0; + case SettingsKey::RESTORE_AUDIO: + return 1; + case SettingsKey::MUTE_ON_SUSPEND: + return 0; + case SettingsKey::MUTE_ON_SHUTDOWN: + return 0; + case SettingsKey::MUTE_ON_LOGOUT: + return 0; + case SettingsKey::QUIETHOURS_ENABLE: + return 0; + case SettingsKey::QUIETHOURS_FORCEUNMUTE: + return 0; + case SettingsKey::QUIETHOURS_NOTIFICATIONS: + return 0; + case SettingsKey::QUIETHOURS_START: + return 0; + case SettingsKey::QUIETHOURS_END: + return 0; + case SettingsKey::LOGGING_ENABLED: + return 0; + case SettingsKey::NOTIFICATIONS_ENABLED: + return 0; + } + return 0; +} + static bool ReadStringFromRegistry(HKEY hKey, const TCHAR* subKey, tstring& val) { bool success = false; @@ -221,12 +261,12 @@ void WMSettings::EnableAutostart(bool enable) } } -DWORD WMSettings::QueryValue(SettingsKey key, DWORD defValue) +DWORD WMSettings::QueryValue(SettingsKey key) const { auto keyStr = KeyToStr(key); assert(keyStr != nullptr); - DWORD value; + DWORD value = 0; DWORD size = sizeof(DWORD); DWORD regError = RegQueryValueEx( hRegSettingsKey_, @@ -235,11 +275,11 @@ DWORD WMSettings::QueryValue(SettingsKey key, DWORD defValue) nullptr, reinterpret_cast(&value), &size); - if (regError == ERROR_FILE_NOT_FOUND) { - return defValue; - } else if (regError != ERROR_SUCCESS) { - PrintWindowsError(_T("RegCreateKeyEx"), regError); - return defValue; + if (regError != ERROR_SUCCESS) { + if (regError != ERROR_FILE_NOT_FOUND) { + PrintWindowsError(_T("RegCreateKeyEx"), regError); + } + return GetDefaultSetting(key); } return value; diff --git a/WinMute/WMSettings.h b/WinMute/WMSettings.h index dd59006..bd718dd 100644 --- a/WinMute/WMSettings.h +++ b/WinMute/WMSettings.h @@ -39,6 +39,7 @@ enum class SettingsKey { MUTE_ON_LOCK , MUTE_ON_SCREENSAVER , MUTE_ON_DISPLAYSTANDBY + , MUTE_ON_RDP , RESTORE_AUDIO , MUTE_ON_SUSPEND , MUTE_ON_SHUTDOWN @@ -66,8 +67,8 @@ public: bool IsAutostartEnabled(); void EnableAutostart(bool enable); - DWORD QueryValue(SettingsKey key, DWORD defValue); - bool SetValue(SettingsKey key, DWORD value); + DWORD QueryValue(SettingsKey key) const; + bool SetValue(SettingsKey key, DWORD value); private: HKEY hRegSettingsKey_; diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index d5371e7..fb294fb 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -95,6 +95,7 @@ static int IsDarkMode(bool& isDarkMode) } WinMute::MuteConfig::MuteConfig() + : showNotifications(false) { this->quietHours.enabled = false; this->quietHours.forceUnmute = false; @@ -168,17 +169,20 @@ bool WinMute::InitAudio() (cond) ? MF_CHECKED : MF_UNCHECKED) != -1) bool WinMute::InitTrayMenu() { - hTrayMenu_ = LoadMenu(hglobInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); - if (!hTrayMenu_) { - PrintWindowsError(_T("LoadMenu")); - return false; - } else if ( - !CHECK_MENU_ITEM(MUTEONLOCK, muteCtrl_.GetMuteOnWorkstationLock()) || - !CHECK_MENU_ITEM(MUTEONSCREENSAVER, muteCtrl_.GetMuteOnScreensaverActivation()) || - !CHECK_MENU_ITEM(RESTOREAUDIO, muteCtrl_.GetRestoreVolume()) || - !CHECK_MENU_ITEM(MUTEONSUSPEND, muteCtrl_.GetMuteOnSuspend()) || - !CHECK_MENU_ITEM(MUTEONSHUTDOWN, muteCtrl_.GetMuteOnShutdown()) || - !CHECK_MENU_ITEM(MUTEONLOGOUT, muteCtrl_.GetMuteOnLogout())) { + if (hTrayMenu_ == NULL) { + hTrayMenu_ = LoadMenu(hglobInstance, MAKEINTRESOURCE(IDR_TRAYMENU)); + if (hTrayMenu_ == NULL) { + PrintWindowsError(_T("LoadMenu")); + return false; + } + } + + if (!CHECK_MENU_ITEM(MUTEONLOCK, muteCtrl_.GetMuteOnWorkstationLock()) || + !CHECK_MENU_ITEM(MUTEONSCREENSAVER, muteCtrl_.GetMuteOnScreensaverActivation()) || + !CHECK_MENU_ITEM(RESTOREAUDIO, muteCtrl_.GetRestoreVolume()) || + !CHECK_MENU_ITEM(MUTEONSUSPEND, muteCtrl_.GetMuteOnSuspend()) || + !CHECK_MENU_ITEM(MUTEONSHUTDOWN, muteCtrl_.GetMuteOnShutdown()) || + !CHECK_MENU_ITEM(MUTEONLOGOUT, muteCtrl_.GetMuteOnLogout())) { return false; } return true; @@ -206,7 +210,7 @@ bool WinMute::Init() return false; } - if (!LoadDefaults()) { + if (!LoadSettings()) { return false; } @@ -255,30 +259,24 @@ bool WinMute::Init() return true; } -bool WinMute::LoadDefaults() +bool WinMute::LoadSettings() { - muteCtrl_.SetRestoreVolume(!!settings_.QueryValue(SettingsKey::RESTORE_AUDIO, 1)); - muteCtrl_.SetMuteOnWorkstationLock(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOCK, 1)); - muteCtrl_.SetMuteOnScreensaverActivation(!!settings_.QueryValue(SettingsKey::MUTE_ON_SCREENSAVER, 1)); - muteCtrl_.SetMuteOnDisplayStandby(!!settings_.QueryValue(SettingsKey::MUTE_ON_DISPLAYSTANDBY, 1)); - muteCtrl_.SetMuteOnLogout(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT, 0)); - muteCtrl_.SetMuteOnSuspend(!!settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND, 0)); - muteCtrl_.SetMuteOnShutdown(!!settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN, 0)); - - muteCtrl_.SetNotifications(settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED, 0) != 0); - - muteConfig_.showNotifications = - settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED, 0) != 0; - muteConfig_.quietHours.enabled = - settings_.QueryValue(SettingsKey::QUIETHOURS_ENABLE, 0) != 0; - muteConfig_.quietHours.forceUnmute = - settings_.QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE, 0) != 0; - muteConfig_.quietHours.notifications = - settings_.QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS, 0) != 0; - muteConfig_.quietHours.start = - settings_.QueryValue(SettingsKey::QUIETHOURS_START, 0); - muteConfig_.quietHours.end = - settings_.QueryValue(SettingsKey::QUIETHOURS_END, 0); + muteCtrl_.SetRestoreVolume(!!settings_.QueryValue(SettingsKey::RESTORE_AUDIO)); + muteCtrl_.SetMuteOnWorkstationLock(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOCK)); + muteCtrl_.SetMuteOnScreensaverActivation(!!settings_.QueryValue(SettingsKey::MUTE_ON_SCREENSAVER)); + muteCtrl_.SetMuteOnDisplayStandby(!!settings_.QueryValue(SettingsKey::MUTE_ON_DISPLAYSTANDBY)); + muteCtrl_.SetMuteOnLogout(!!settings_.QueryValue(SettingsKey::MUTE_ON_LOGOUT)); + muteCtrl_.SetMuteOnSuspend(!!settings_.QueryValue(SettingsKey::MUTE_ON_SUSPEND)); + muteCtrl_.SetMuteOnShutdown(!!settings_.QueryValue(SettingsKey::MUTE_ON_SHUTDOWN)); + + muteCtrl_.SetNotifications(!!settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED)); + + muteConfig_.showNotifications = !!settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED); + muteConfig_.quietHours.enabled = !!settings_.QueryValue(SettingsKey::QUIETHOURS_ENABLE); + muteConfig_.quietHours.forceUnmute = !!settings_.QueryValue(SettingsKey::QUIETHOURS_FORCEUNMUTE); + muteConfig_.quietHours.notifications = !!settings_.QueryValue(SettingsKey::QUIETHOURS_NOTIFICATIONS); + muteConfig_.quietHours.start = settings_.QueryValue(SettingsKey::QUIETHOURS_START); + muteConfig_.quietHours.end = settings_.QueryValue(SettingsKey::QUIETHOURS_END); return true; } @@ -320,15 +318,15 @@ LRESULT CALLBACK WinMute::WindowProc( SendMessage(hWnd, WM_CLOSE, 0, 0); break; case ID_TRAYMENU_SETTINGS: { - DialogBoxParam( - hglobInstance, - MAKEINTRESOURCE(IDD_SETTINGS), - hWnd_, - SettingsDlgProc, - reinterpret_cast(&settings_)); - bool notifications = settings_.QueryValue(SettingsKey::NOTIFICATIONS_ENABLED, 0) != 0; - muteConfig_.showNotifications = notifications; - muteCtrl_.SetNotifications(notifications); + if (DialogBoxParam( + hglobInstance, + MAKEINTRESOURCE(IDD_SETTINGS), + hWnd_, + SettingsDlgProc, + reinterpret_cast(&settings_)) == 0) { + LoadSettings(); + InitTrayMenu(); + } break; } case ID_TRAYMENU_MUTE: { @@ -471,14 +469,11 @@ LRESULT CALLBACK WinMute::WindowProc( return 0; case WM_WINMUTE_QUIETHOURS_CHANGE: { muteConfig_.quietHours.enabled = settings_.QueryValue( - SettingsKey::QUIETHOURS_ENABLE, - 0); + SettingsKey::QUIETHOURS_ENABLE); muteConfig_.quietHours.forceUnmute = settings_.QueryValue( - SettingsKey::QUIETHOURS_FORCEUNMUTE, - 0); + SettingsKey::QUIETHOURS_FORCEUNMUTE); muteConfig_.quietHours.notifications = settings_.QueryValue( - SettingsKey::QUIETHOURS_NOTIFICATIONS, - 0); + SettingsKey::QUIETHOURS_NOTIFICATIONS); CheckMenuItem( hTrayMenu_, ID_TRAYMENU_CONFIGUREQUIETHOURS, @@ -486,11 +481,9 @@ LRESULT CALLBACK WinMute::WindowProc( if (muteConfig_.quietHours.enabled) { muteConfig_.quietHours.start = settings_.QueryValue( - SettingsKey::QUIETHOURS_START, - 0); + SettingsKey::QUIETHOURS_START); muteConfig_.quietHours.end = settings_.QueryValue( - SettingsKey::QUIETHOURS_END, - 0); + SettingsKey::QUIETHOURS_END); } ResetQuietHours(); @@ -620,13 +613,39 @@ void WinMute::ResetQuietHours() int timerQhEnd = GetDiffMillseconds(&end, &now); WMLog::GetInstance().Write(L"Mute: On | Quiet hours have already started"); muteCtrl_.NotifyQuietHours(true); - if (SetTimer(hWnd_, QUIETHOURS_TIMER_END_ID, timerQhEnd, QuietHoursTimer) == 0) { - MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); + if (SetCoalescableTimer( + hWnd_, + QUIETHOURS_TIMER_END_ID, + timerQhEnd, + QuietHoursTimer, + TIMERV_DEFAULT_COALESCING) == 0) { + TaskDialog( + hWnd_, + hglobInstance, + PROGRAM_NAME, + _T("Quiet Hours Stop"), + _T("Failed to register end of quiet hours with windows timer system"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); } } else { int timerQhStart = GetDiffMillseconds(&start, &now); - if (SetTimer(hWnd_, QUIETHOURS_TIMER_START_ID, timerQhStart, QuietHoursTimer) == 0) { - MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); + if (SetCoalescableTimer( + hWnd_, + QUIETHOURS_TIMER_START_ID, + timerQhStart, + QuietHoursTimer, + TIMERV_DEFAULT_COALESCING) == 0) { + TaskDialog( + hWnd_, + hglobInstance, + PROGRAM_NAME, + _T("Quiet Hours Start"), + _T("Failed to register quiet hours start with windows timer system"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); } } } @@ -645,8 +664,21 @@ void WinMute::SetQuietHoursStart() start.wHour = static_cast((muteConfig_.quietHours.start - start.wMinute - start.wSecond) / 3600); int timerQhStart = GetDiffMillseconds(&start, &now); - if (SetTimer(hWnd_, QUIETHOURS_TIMER_START_ID, timerQhStart, QuietHoursTimer) == 0) { - MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); + if (SetCoalescableTimer( + hWnd_, + QUIETHOURS_TIMER_START_ID, + timerQhStart, + QuietHoursTimer, + TIMERV_DEFAULT_COALESCING) == 0) { + TaskDialog( + hWnd_, + hglobInstance, + PROGRAM_NAME, + _T("Quiet Hours Start"), + _T("Failed to register quiet hours start with windows timer system"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); } } @@ -665,8 +697,21 @@ void WinMute::SetQuietHoursEnd() int timerQhEnd = GetDiffMillseconds(&end, &now); if (timerQhEnd <= 0) { SendMessage(hWnd_, WM_WINMUTE_QUIETHOURS_END, 0, 0); - } else if (SetTimer(hWnd_, QUIETHOURS_TIMER_END_ID, timerQhEnd, QuietHoursTimer) == 0) { - MessageBox(hWnd_, L"Failed to create Timer", PROGRAM_NAME, MB_OK); + } else if (SetCoalescableTimer( + hWnd_, + QUIETHOURS_TIMER_END_ID, + timerQhEnd, + QuietHoursTimer, + TIMERV_DEFAULT_COALESCING) == 0) { + TaskDialog( + hWnd_, + hglobInstance, + PROGRAM_NAME, + _T("Quiet Hours Stop"), + _T("Failed to register end of quiet hours with windows timer system"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); } } diff --git a/WinMute/WinMute.h b/WinMute/WinMute.h index 03f85f9..88b2a72 100644 --- a/WinMute/WinMute.h +++ b/WinMute/WinMute.h @@ -80,8 +80,7 @@ private: bool InitWindow(); bool InitAudio(); bool InitTrayMenu(); - void InitMuteSettings(); - bool LoadDefaults(); + bool LoadSettings(); void ResetQuietHours(); void SetQuietHoursStart(); diff --git a/WinMute/WinMute.rc b/WinMute/WinMute.rc index ccc510a..f251a36 100644 --- a/WinMute/WinMute.rc +++ b/WinMute/WinMute.rc @@ -71,29 +71,29 @@ BEGIN CONTROL "",IDC_SETTINGS_TAB,"SysTabControl32",0x0,7,7,255,223 END -IDD_SETTINGS_GENERAL DIALOGEX 0, 0, 201, 179 +IDD_SETTINGS_GENERAL DIALOGEX 0, 0, 233, 179 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN CONTROL "Start WinMute on system startup",IDC_RUNONSTARTUP, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,15,187,26 - CONTROL "Enable Logging",IDC_ENABLELOGGING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,61,187,21 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,3,219,26 + CONTROL "Enable Logging",IDC_ENABLELOGGING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,48,219,21 CONTROL "Show mute event notifications",IDC_SHOWNOTIFICATIONS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,39,187,21 - PUSHBUTTON "Open Log File...",IDC_OPENLOG,22,82,58,15 + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,27,219,21 + PUSHBUTTON "Open Log File...",IDC_OPENLOG,22,69,58,15 END -IDD_SETTINGS_QUIETHOURS DIALOGEX 0, 0, 234, 177 +IDD_SETTINGS_QUIETHOURS DIALOGEX 0, 0, 246, 198 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN - LTEXT "During Quiet Hours WinMute automatically mutes your PC volumes and unmutes it afterwards.",IDC_STATIC,7,7,220,22 + LTEXT "During Quiet Hours WinMute automatically mutes your PC volumes and unmutes it afterwards.",IDC_STATIC,7,9,232,22 CONTROL "Enable Quiet Hours",IDC_ENABLEQUIETHOURS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,31,120,15 CONTROL "",IDC_QUIETHOURS_START,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,73,47,65,18 CONTROL "",IDC_QUIETHOURS_END,"SysDateTimePick32",DTS_RIGHTALIGN | DTS_UPDOWN | WS_TABSTOP | 0x8,72,71,67,19 CONTROL "Force unmute",IDC_FORCEUNMUTE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,94,86,16 CONTROL "Show notifications",IDC_SHOWNOTIFICATIONS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,146,81,21 - LTEXT "If force unmute is enabled, WinMute will unmute your workstation when quiet hours end and not take into account if your workstation was already muted before quiet hours started.",IDC_STATIC,23,111,204,37 + LTEXT "If force unmute is enabled, WinMute will unmute your workstation when quiet hours end and not take into account if your workstation was already muted before quiet hours started.",IDC_STATIC,33,111,204,37 LTEXT "Start time:",IDC_STATIC,23,50,43,13 LTEXT "End time:",IDC_STATIC,24,73,32,16 END @@ -118,6 +118,29 @@ BEGIN "SysLink",WS_TABSTOP,197,49,94,14 END +IDD_SETTINGS_MUTE DIALOGEX 0, 0, 242, 205 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + GROUPBOX "Mute with volume restore, when...",IDC_STATIC,7,33,228,104 + CONTROL "... the workstation is locked",IDC_MUTE_WHEN_WS_LOCKED, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,48,105,10 + CONTROL "... the screensaver starts",IDC_MUTE_WHEN_SCREENSAVER_STARTS, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,62,99,10 + CONTROL "... the screen turns off",IDC_MUTE_WHEN_SCREEN_OFF, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,76,90,10 + CONTROL "... a remote session is started",IDC_MUTE_WHEN_RDP_SESSION, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,90,112,10 + CONTROL "Restore volume afterwards",IDC_RESTOREVOLUME,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,105,103,10 + GROUPBOX "Mute without volume restore, when...",IDC_STATIC,7,139,228,59 + CONTROL "... the computer shuts down",IDC_MUTE_WHEN_SHUTDOWN, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,153,107,10 + CONTROL "... you log out",IDC_MUTE_WHEN_LOGOUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,181,62,10 + CONTROL "... the computer goes into sleep/hibernate.",IDC_MUTE_WHEN_SLEEP, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,20,167,155,10 + LTEXT "Here you can configure the various mute conditions and variations that WinMute supports.",IDC_STATIC,7,8,228,17 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -146,7 +169,7 @@ BEGIN IDD_SETTINGS_GENERAL, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 194 + RIGHTMARGIN, 226 TOPMARGIN, 7 BOTTOMMARGIN, 172 END @@ -154,9 +177,9 @@ BEGIN IDD_SETTINGS_QUIETHOURS, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 227 + RIGHTMARGIN, 239 TOPMARGIN, 7 - BOTTOMMARGIN, 170 + BOTTOMMARGIN, 191 END IDD_ABOUT_LICENSE, DIALOG @@ -174,6 +197,14 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 169 END + + IDD_SETTINGS_MUTE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 235 + TOPMARGIN, 7 + BOTTOMMARGIN, 198 + END END #endif // APSTUDIO_INVOKED @@ -214,6 +245,11 @@ BEGIN 0 END +IDD_SETTINGS_MUTE AFX_DIALOG_LAYOUT +BEGIN + 0 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -246,8 +282,7 @@ BEGIN MENUITEM "... Workstation is locked", ID_TRAYMENU_MUTEONLOCK, CHECKED MENUITEM "... Screensaver starts", ID_TRAYMENU_MUTEONSCREENSAVER, CHECKED MENUITEM "... Screen turns off", ID_TRAYMENU_SCREENSUSPEND, CHECKED - MENUITEM SEPARATOR - MENUITEM "Restore previous volume afterwards", ID_TRAYMENU_RESTOREAUDIO, CHECKED + MENUITEM "Restore volume afterwards", ID_TRAYMENU_RESTOREAUDIO, CHECKED MENUITEM SEPARATOR MENUITEM "Mute on (no volume restore)", ID_TRAYMENU_AFTERWARDS, INACTIVE MENUITEM "... Shutdown", ID_TRAYMENU_MUTEONSHUTDOWN diff --git a/WinMute/WinMute.vcxproj b/WinMute/WinMute.vcxproj index b23e2cf..3ef9618 100644 --- a/WinMute/WinMute.vcxproj +++ b/WinMute/WinMute.vcxproj @@ -222,6 +222,7 @@ Create Create + diff --git a/WinMute/WinMute.vcxproj.filters b/WinMute/WinMute.vcxproj.filters index 257cdbb..427e71c 100644 --- a/WinMute/WinMute.vcxproj.filters +++ b/WinMute/WinMute.vcxproj.filters @@ -167,5 +167,8 @@ Source Files\UI\Dialogs + + Source Files\UI\Dialogs\Settings + \ No newline at end of file diff --git a/WinMute/resource.h b/WinMute/resource.h index 8e77249..fd5d380 100644 --- a/WinMute/resource.h +++ b/WinMute/resource.h @@ -14,6 +14,7 @@ #define IDD_ABOUT_WINMUTE 120 #define IDI_ICON1 122 #define IDI_SETTINGS 122 +#define IDD_SETTINGS_MUTE 123 #define IDC_LINK_HOMEPAGE 1001 #define IDC_LINK_SUPPORT 1002 #define IDC_LINK_PROJECT 1002 @@ -28,14 +29,24 @@ #define IDC_SETTINGS_TAB 1010 #define IDC_CHECK1 1011 #define IDC_RUNONSTARTUP 1011 +#define IDC_MUTE_WHEN_WS_LOCKED 1011 #define IDC_ENABLELOGGING 1012 #define IDC_CHECK3 1013 +#define IDC_ENABLESTOPPLAYBACK 1013 #define IDC_OPENLOG 1014 #define IDC_LICENSETEXT 1015 #define IDC_ABOUT_TAB 1016 #define IDC_ABOUTTEXT 1019 #define IDC_TITLE 1020 #define IDC_ABOUT_TITLE 1020 +#define IDC_MUTE_WHEN_SCREENSAVER_STARTS 1021 +#define IDC_MUTE_WHEN_SCREEN_OFF 1022 +#define IDC_MUTE_WHEN_RDP_SESSION 1023 +#define IDC_RESTOREVOLUME 1024 +#define IDC_MUTE_WHEN_SHUTDOWN 1025 +#define IDC_MUTE_WHEN_RDP_SESSION3 1026 +#define IDC_MUTE_WHEN_LOGOUT 1026 +#define IDC_MUTE_WHEN_SLEEP 1027 #define ID_TRAYMENU_INFO 40001 #define ID_TRAYMENU_ 40002 #define ID_TRAYMENU_MUTEON 40003 @@ -68,9 +79,9 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 123 +#define _APS_NEXT_RESOURCE_VALUE 125 #define _APS_NEXT_COMMAND_VALUE 40028 -#define _APS_NEXT_CONTROL_VALUE 1021 +#define _APS_NEXT_CONTROL_VALUE 1022 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- 2.43.0