]> repos.lx-s.de Git - winmute.git/commitdiff
Bumped version. Replaced MessageBoxes with TaskDialog.
authorlx-s <lx-s@users.noreply.github.com>
Thu, 11 Aug 2016 11:12:15 +0000 (13:12 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Thu, 11 Aug 2016 11:12:15 +0000 (13:12 +0200)
Also: Code Cleanups

ScreensaverNotify/ScreensaverNotify.cpp
WinMute/MMNotificationClient.cpp
WinMute/ScreensaverNotifier.cpp
WinMute/Settings.cpp
WinMute/Utility.cpp
WinMute/VistaAudio.cpp
WinMute/VistaAudioSessionEvents.cpp
WinMute/WinMain.cpp
WinMute/WinMute.cpp
WinMute/res.rc

index bb4b82b78cdbc787013619218f20d8955a46d24b..30e71aaf360511bbaaef15000283b853dc66c867 100644 (file)
@@ -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<HOOKPROC>(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;
       }
 
index fbaaf223c6da2a6b82ba8987286c52a89a2c98d9..d7c0c9bdded101f22f6cde2738c5daa2caa77a90 100644 (file)
@@ -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;
index 3bb821b2bccb9687a1c837718de067c88a74e8f8..1865440e5f3a6465de521f99b69bce5ceb778684 100644 (file)
@@ -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<UnregisterHook>(
             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;
    }
index 1cb34393e0263e9ea16833f76f1ca81d9790baa0..63ff608dda3f06616a8c30f88cd215ab5e098275 100644 (file)
@@ -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<LPBYTE>(&value),
                                     &size);
    if (regError == ERROR_FILE_NOT_FOUND) {
index c2972eb911596496268923bbfa2dfdefb438a347..79a034e8b02f8f3cf85d4718da6a4c3af6bfc14a 100644 (file)
@@ -60,10 +60,14 @@ void PrintWindowsError(LPTSTR lpszFunction, DWORD lastError)
                          lpszFunction,
                          lastError,
                          reinterpret_cast<TCHAR*>(lpMsgBuf));
-
-         MessageBox(nullptr, static_cast<LPCTSTR>(lpDisplayBuf), _T("Error"),
-                    MB_ICONERROR | MB_OK);
-
+         TaskDialog(nullptr,
+                    nullptr,
+                    PROGRAM_NAME,
+                    static_cast<LPCTSTR>(lpDisplayBuf),
+                    nullptr,
+                    TDCBF_OK_BUTTON,
+                    TD_ERROR_ICON,
+                    nullptr);
          LocalFree(lpDisplayBuf);
       }
       LocalFree(lpMsgBuf);
index 020f9ea4007511306c94d51a973fdd65557608b6..98c0342aff6265a980cf5963c566da95d8e4a7c0 100644 (file)
@@ -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<LPVOID*>(&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<LPVOID*>(&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;
    }
index e35dc223297c711e16e238d972cd642dd6fd0ae1..5ac9f6f2e1aab0935f5984bfee51ef3267c6b285 100644 (file)
@@ -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;
index 46525e9b3b7f9b7b2db5572f3ced995887447e23..58caed69b4764e4e3bc7cf10bb2b6a81212ff861 100644 (file)
@@ -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,
 
    // <Init COM>
    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;
    }
index ddd7fb7a21f29cee7edf06af478b49c74d81496a..83cabfcd25f509dd91e65a247322fcc21c6a47bc 100644 (file)
@@ -102,8 +102,15 @@ bool WinMute::InitAudio()
    if (IsWindowsVistaOrGreater()) {
       audio_ = std::unique_ptr<WinAudio>(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;
    }
 
index f8c327c8599ff43675ba6b5de8b84c28fb9a6af0..afd968bfd0f217f369ab8c22ac727a58c400093c 100644 (file)
@@ -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         "<a href=""http://lx-s.de"">lx-systems - lx-s.de</a>",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
 /////////////////////////////////////////////////////////////////////////////