From df1d14450441cd663cf3b4f7445637b0de32cf35 Mon Sep 17 00:00:00 2001 From: lx-s Date: Thu, 11 Aug 2016 13:12:15 +0200 Subject: [PATCH] Bumped version. Replaced MessageBoxes with TaskDialog. Also: Code Cleanups --- ScreensaverNotify/ScreensaverNotify.cpp | 18 +++++------ WinMute/MMNotificationClient.cpp | 4 +-- WinMute/ScreensaverNotifier.cpp | 12 ++++---- WinMute/Settings.cpp | 8 ++--- WinMute/Utility.cpp | 12 +++++--- WinMute/VistaAudio.cpp | 41 ++++++++++++++++++++----- WinMute/VistaAudioSessionEvents.cpp | 13 +++++--- WinMute/WinMain.cpp | 36 ++++++++++++++++------ WinMute/WinMute.cpp | 11 +++++-- WinMute/res.rc | 40 +++++++++++++++--------- 10 files changed, 133 insertions(+), 62 deletions(-) diff --git a/ScreensaverNotify/ScreensaverNotify.cpp b/ScreensaverNotify/ScreensaverNotify.cpp index bb4b82b..30e71aa 100644 --- a/ScreensaverNotify/ScreensaverNotify.cpp +++ b/ScreensaverNotify/ScreensaverNotify.cpp @@ -42,13 +42,13 @@ POSSIBILITY OF SUCH DAMAGE. ========================================================================== */ #pragma data_seg(".shared") -static HHOOK hook_ = NULL; -static HWND hNotifyWnd_ = NULL; +static HHOOK hook_ = nullptr; +static HWND hNotifyWnd_ = nullptr; static UINT notifyWndMsgId_ = 0; #pragma data_seg() #pragma comment(linker, "/SECTION:.shared,RWS") -static HINSTANCE hglobInstance_ = NULL; +static HINSTANCE hglobInstance_ = nullptr; /* ============================================================================= Hook Function @@ -75,7 +75,7 @@ extern "C" { WINMUTEDLL_API int RegisterScreensaverHook(HWND hNotifyWnd, UINT notifyWndMsgId) { - if (hook_ != NULL) { + if (hook_ != nullptr) { UnregisterScreensaverHook(); } hNotifyWnd_ = hNotifyWnd; @@ -84,15 +84,15 @@ extern "C" { reinterpret_cast(MsgHookProc), hglobInstance_, 0); - return hook_ != NULL; + return hook_ != nullptr; } WINMUTEDLL_API void UnregisterScreensaverHook() { - if (hook_ != NULL) { + if (hook_ != nullptr) { UnhookWindowsHookEx(hook_); - hook_ = NULL; - hNotifyWnd_ = NULL; + hook_ = nullptr; + hNotifyWnd_ = nullptr; notifyWndMsgId_ = 0; } } @@ -101,7 +101,7 @@ extern "C" { { UNREFERENCED_PARAMETER(lpReserved); - if ((reason == DLL_PROCESS_ATTACH) && (hglobInstance_ == NULL)) { + if ((reason == DLL_PROCESS_ATTACH) && (hglobInstance_ == nullptr)) { hglobInstance_ = hInstance; } diff --git a/WinMute/MMNotificationClient.cpp b/WinMute/MMNotificationClient.cpp index fbaaf22..d7c0c9b 100644 --- a/WinMute/MMNotificationClient.cpp +++ b/WinMute/MMNotificationClient.cpp @@ -38,7 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. class WinAudio; MMNotificationClient::MMNotificationClient(WinAudio* notifyParent) : - ref_(1), pEnumerator_(NULL), notifyParent_(notifyParent) + ref_(1), pEnumerator_(nullptr), notifyParent_(notifyParent) { } @@ -72,7 +72,7 @@ HRESULT STDMETHODCALLTYPE MMNotificationClient::QueryInterface( AddRef(); *ppvInterface = (IMMNotificationClient*)this; } else { - *ppvInterface = NULL; + *ppvInterface = nullptr; return E_NOINTERFACE; } return S_OK; diff --git a/WinMute/ScreensaverNotifier.cpp b/WinMute/ScreensaverNotifier.cpp index 3bb821b..1865440 100644 --- a/WinMute/ScreensaverNotifier.cpp +++ b/WinMute/ScreensaverNotifier.cpp @@ -104,14 +104,14 @@ bool ScreensaverNotifier::InitWindow() { hWnd_ = CreateWindowEx(WS_EX_TOOLWINDOW, SCRSVER_NOTIFY_WND_CLASS, - NULL, + nullptr, WS_POPUP, 0, 0, 0, 0, HWND_MESSAGE, 0, hglobInstance, this); - if (hWnd_ == NULL) { + if (hWnd_ == nullptr) { PrintWindowsError(_T("CreateWindow")); return false; } @@ -139,12 +139,12 @@ bool ScreensaverNotifier::InitHookDll() GetProcAddress(hookDll_, "RegisterScreensaverHook")); unregHook_ = reinterpret_cast( GetProcAddress(hookDll_, "UnregisterScreensaverHook")); - if (regHook_ == NULL || unregHook_ == NULL) { + if (regHook_ == nullptr || unregHook_ == nullptr) { Unload(); } } } - return hookDll_ != NULL; + return hookDll_ != nullptr; } @@ -197,7 +197,7 @@ void ScreensaverNotifier::ClearNotifications() void ScreensaverNotifier::StartScreensaverPollTimer(bool start) { if (start) { - if (SetTimer(hWnd_, SCRSV_TIMER_ID, 1000, NULL) == 0) { + if (SetTimer(hWnd_, SCRSV_TIMER_ID, 1000, nullptr) == 0) { PrintWindowsError(_T("SetTimer")); } } else { @@ -215,7 +215,7 @@ bool ScreensaverNotifier::IsScreensaverRunning() if (SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &isRunning, - FALSE) == NULL) { + FALSE) == FALSE) { PrintWindowsError(_T("SystemParametersInfo")); return false; } diff --git a/WinMute/Settings.cpp b/WinMute/Settings.cpp index 1cb3439..63ff608 100644 --- a/WinMute/Settings.cpp +++ b/WinMute/Settings.cpp @@ -70,12 +70,12 @@ bool Settings::Init() DWORD regError = RegCreateKeyEx(HKEY_CURRENT_USER, LX_SYSTEMS_SUBKEY, 0, - NULL, + nullptr, 0, KEY_READ | KEY_WRITE, - NULL, + nullptr, &hRegSettingsKey_, - NULL); + nullptr); if (regError != ERROR_SUCCESS) { PrintWindowsError(_T("RegCreateKeyEx"), regError); return false; @@ -101,7 +101,7 @@ DWORD Settings::QueryValue(SettingsKey key, DWORD defValue) DWORD regError = RegQueryValueEx(hRegSettingsKey_, keyStr, 0, - NULL, + nullptr, reinterpret_cast(&value), &size); if (regError == ERROR_FILE_NOT_FOUND) { diff --git a/WinMute/Utility.cpp b/WinMute/Utility.cpp index c2972eb..79a034e 100644 --- a/WinMute/Utility.cpp +++ b/WinMute/Utility.cpp @@ -60,10 +60,14 @@ void PrintWindowsError(LPTSTR lpszFunction, DWORD lastError) lpszFunction, lastError, reinterpret_cast(lpMsgBuf)); - - MessageBox(nullptr, static_cast(lpDisplayBuf), _T("Error"), - MB_ICONERROR | MB_OK); - + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + static_cast(lpDisplayBuf), + nullptr, + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); LocalFree(lpDisplayBuf); } LocalFree(lpMsgBuf); diff --git a/WinMute/VistaAudio.cpp b/WinMute/VistaAudio.cpp index 020f9ea..98c0342 100644 --- a/WinMute/VistaAudio.cpp +++ b/WinMute/VistaAudio.cpp @@ -72,8 +72,15 @@ bool VistaAudio::Init(HWND hParent) IMMDevice *defaultDevice = nullptr; if(FAILED(deviceEnumerator_->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice))) { - MessageBox(0, _T("Failed to get default audio endpoint device"), - PROGRAM_NAME, MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to get default audio endpoint device"), + _T("WinMute is not able to recover from that condition.\n") + _T("Please try restarting the program"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); return false; } @@ -82,16 +89,28 @@ bool VistaAudio::Init(HWND hParent) if (FAILED(defaultDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_INPROC_SERVER, nullptr, reinterpret_cast(&sessionManager2)))) { - MessageBox(0, _T("Failed to retrieve audio session manager."), - PROGRAM_NAME, MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to retrieve audio session manager."), + _T("Please try restarting the program"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); SafeRelease(&defaultDevice); return false; } if (FAILED(sessionManager2->GetAudioSessionControl(nullptr, 0, &sessionControl_))) { - MessageBox(0, _T("Failed to retrieve session control."), PROGRAM_NAME, - MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to retrieve session control."), + _T("Please try restarting the program"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); SafeRelease(&sessionManager2); return false; } @@ -109,8 +128,14 @@ bool VistaAudio::Init(HWND hParent) if (FAILED(defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, nullptr, reinterpret_cast(&endpointVolume_)))) { - MessageBox(0, _T("Failed to activate default audio device."), - PROGRAM_NAME, MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to activate default audio device."), + _T("Please try restarting the program"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); SafeRelease(&defaultDevice); return false; } diff --git a/WinMute/VistaAudioSessionEvents.cpp b/WinMute/VistaAudioSessionEvents.cpp index e35dc22..5ac9f6f 100644 --- a/WinMute/VistaAudioSessionEvents.cpp +++ b/WinMute/VistaAudioSessionEvents.cpp @@ -135,10 +135,15 @@ HRESULT STDMETHODCALLTYPE VistaAudioSessionEvents::OnSessionDisconnected( notifyParent_->ShouldReInit(); break; case DisconnectReasonServerShutdown: - MessageBox(0, _T("The audio service has been shut down. ") - _T("WinMute is not able to recover from that condition.\n") - _T("Please try restarting the program"), PROGRAM_NAME, - MB_ICONWARNING | MB_OK); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("The audio service has been shut down. "), + _T("WinMute is not able to recover from that condition.\n") + _T("Please try restarting the program"), + TDCBF_OK_BUTTON, + TD_WARNING_ICON, + nullptr); break; case DisconnectReasonSessionLogoff: break; diff --git a/WinMute/WinMain.cpp b/WinMute/WinMain.cpp index 46525e9..58caed6 100644 --- a/WinMute/WinMain.cpp +++ b/WinMute/WinMain.cpp @@ -41,13 +41,20 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_ int) { HANDLE hMutex = CreateMutex(nullptr, TRUE, _T("LxSystemsWinMute")); - if (hMutex == NULL) { + if (hMutex == nullptr) { return FALSE; } if (GetLastError() == ERROR_ALREADY_EXISTS) { ReleaseMutex(hMutex); - MessageBox(0, _T("WinMute is already running."), PROGRAM_NAME, - MB_ICONINFORMATION); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("WinMute is already running"), + _T("Please look for a blue speaker icon in your Windows ") + _T(" taskbar notification area."), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); return FALSE; } @@ -59,10 +66,15 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, INITCOMMONCONTROLSEX initComCtrl; initComCtrl.dwSize = sizeof(INITCOMMONCONTROLSEX); initComCtrl.dwICC = ICC_LINK_CLASS; - if (InitCommonControlsEx(&initComCtrl) == FALSE){ - MessageBox(0, _T("Fatal Error:\n") - _T("Failed to register extended window controls"), - PROGRAM_NAME, MB_ICONSTOP); + if (InitCommonControlsEx(&initComCtrl) == FALSE) { + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to register extended window controls."), + _T("Please try to restart the program."), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); ReleaseMutex(hMutex); return FALSE; } @@ -70,8 +82,14 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, // if (CoInitializeEx(0, COINIT_APARTMENTTHREADED) != S_OK) { - MessageBox(0, _T("Fatal Error:\nFailed to initialize COM library."), - PROGRAM_NAME, MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Failed to initialize COM library."), + _T("Please try to restart the program."), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); ReleaseMutex(hMutex); return FALSE; } diff --git a/WinMute/WinMute.cpp b/WinMute/WinMute.cpp index ddd7fb7..83cabfc 100644 --- a/WinMute/WinMute.cpp +++ b/WinMute/WinMute.cpp @@ -102,8 +102,15 @@ bool WinMute::InitAudio() if (IsWindowsVistaOrGreater()) { audio_ = std::unique_ptr(new VistaAudio); } else if (IsWindowsXPOrGreater()) { - MessageBox(0, _T("Only Windows Vista and newer is supported"), - 0, MB_ICONERROR); + TaskDialog(nullptr, + nullptr, + PROGRAM_NAME, + _T("Only Windows Vista and newer is supported"), + _T("For Windows XP support, please download WinMute ") + _T(" version 1.4.2 or older"), + TDCBF_OK_BUTTON, + TD_ERROR_ICON, + nullptr); return false; } diff --git a/WinMute/res.rc b/WinMute/res.rc index f8c327c..afd968b 100644 --- a/WinMute/res.rc +++ b/WinMute/res.rc @@ -56,11 +56,11 @@ BEGIN BEGIN MENUITEM "Info", ID_TRAYMENU_INFO MENUITEM SEPARATOR - MENUITEM "Mute on ...", ID_TRAYMENU_MUTEON, INACTIVE - MENUITEM "... Workstation lock", ID_TRAYMENU_MUTEONLOCK, CHECKED - MENUITEM "... Screensaver start", ID_TRAYMENU_MUTEONSCREENSAVER, CHECKED + MENUITEM "Mute when ...", ID_TRAYMENU_MUTEON, INACTIVE + MENUITEM "... Workstation is locked", ID_TRAYMENU_MUTEONLOCK, CHECKED + MENUITEM "... Screensaver starts", ID_TRAYMENU_MUTEONSCREENSAVER, CHECKED MENUITEM SEPARATOR - MENUITEM "Restore Audio", ID_TRAYMENU_RESTOREAUDIO, CHECKED + MENUITEM "Restore Volume", ID_TRAYMENU_RESTOREAUDIO, CHECKED MENUITEM SEPARATOR MENUITEM "Mute now", ID_TRAYMENU_MUTE MENUITEM SEPARATOR @@ -80,10 +80,10 @@ CAPTION "About WinMute" FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN DEFPUSHBUTTON "OK",IDOK,194,7,50,14 - LTEXT "WinMute v1.4.2",IDC_STATIC,43,9,67,11 + LTEXT "WinMute v1.4.3",IDC_STATIC,43,9,67,11 CONTROL "lx-systems - lx-s.de",IDC_LINK_HOMEPAGE, "SysLink",WS_TABSTOP,43,31,69,13 - LTEXT "Copyright © 2014 Alexander Steinhöfer",IDC_STATIC,43,20,148,12 + LTEXT "Copyright © 2016, Alexander Steinhöfer",IDC_STATIC,43,20,148,12 ICON IDI_APP,IDC_STATIC,13,7,20,20 END @@ -114,8 +114,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,4,2,0 - PRODUCTVERSION 1,4,2,0 + FILEVERSION 1,4,3,0 + PRODUCTVERSION 1,4,3,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -132,23 +132,23 @@ BEGIN BEGIN VALUE "CompanyName", "lx-systems" VALUE "FileDescription", "Automatic sound muter." - VALUE "FileVersion", "1.4.2.0" + VALUE "FileVersion", "1.4.3.0" VALUE "InternalName", "WinMute" - VALUE "LegalCopyright", "Copyright (C) 2014, Alexander Steinhöfer" + VALUE "LegalCopyright", "Copyright (C) 2016, Alexander Steinhöfer" VALUE "OriginalFilename", "WinMute.exe" VALUE "ProductName", "WinMute" - VALUE "ProductVersion", "1.4.2.0" + VALUE "ProductVersion", "1.4.3.0" END BLOCK "040704b0" BEGIN VALUE "CompanyName", "lx-systems" VALUE "FileDescription", "Automatisches Stummschalten bei PC Sperre." - VALUE "FileVersion", "1.4.2.0" + VALUE "FileVersion", "1.4.3.0" VALUE "InternalName", "WinMute" - VALUE "LegalCopyright", "Copyright (C) 2014, Alexander Steinhöfer" + VALUE "LegalCopyright", "Copyright (C) 2016, Alexander Steinhöfer" VALUE "OriginalFilename", "WinMute.exe" VALUE "ProductName", "WinMute" - VALUE "ProductVersion", "1.4.2.0" + VALUE "ProductVersion", "1.4.3.0" END END BLOCK "VarFileInfo" @@ -166,6 +166,18 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDI_APP ICON "app.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// AFX_DIALOG_LAYOUT +// + +IDD_ABOUT AFX_DIALOG_LAYOUT +BEGIN + 0 +END + #endif // German (Germany) resources ///////////////////////////////////////////////////////////////////////////// -- 2.43.0