]> repos.lx-s.de Git - winmute.git/commitdiff
Improved UI when WiFi/BT is not available.
authorAlexander Steinhöfer <kontakt@lx-s.de>
Wed, 3 Aug 2022 07:31:45 +0000 (09:31 +0200)
committerAlexander Steinhöfer <kontakt@lx-s.de>
Wed, 3 Aug 2022 07:31:45 +0000 (09:31 +0200)
WinMute/Settings_BluetoothDlg.cpp
WinMute/Settings_WifiDlg.cpp
WinMute/WifiDetector.cpp

index 854886d0084cb3e12bc30a7aedcdf5c026db4e66..eb9f6e3964541cc11aaaafb1614dd43e939d9edf 100644 (file)
@@ -169,6 +169,12 @@ static bool IsBluetoothAvailable()
    return true;
 }
 
+static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam)
+{
+   ShowWindow(hWnd, static_cast<int>(lParam));
+   return TRUE;
+}
+
 INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
    switch (msg) {
@@ -205,13 +211,24 @@ INT_PTR CALLBACK Settings_BluetoothDlgProc(HWND hDlg, UINT msg, WPARAM wParam, L
          ListBox_GetCount(hList) > 0);
 
       if (!IsBluetoothAvailable()) {
-         ShowWindow(GetDlgItem(hDlg, IDC_STATIC_BLUETOOTH_NOT_AVAILABLE), SW_SHOW);
+         // Set defaults
          Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE), BST_UNCHECKED);
          Button_Enable(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE), FALSE);
          Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE_DEVICE_LIST), BST_UNCHECKED);
          Button_Enable(GetDlgItem(hDlg, IDC_ENABLE_BLUETOOTH_MUTE_DEVICE_LIST), FALSE);
-      }
-      else {
+
+         // Hide all child windows, except the notice
+         EnumChildWindows(hDlg, ShowChildWindow, SW_HIDE);
+
+         HWND hBtNotAvail = GetDlgItem(hDlg, IDC_STATIC_BLUETOOTH_NOT_AVAILABLE);
+         RECT r;
+         GetClientRect(hBtNotAvail, &r);
+         const int margin = 20;
+         SetWindowPos(
+            hBtNotAvail, HWND_TOP,
+            margin, margin, r.right, r.bottom,
+            SWP_SHOWWINDOW);
+      } else {
          ShowWindow(GetDlgItem(hDlg, IDC_STATIC_BLUETOOTH_NOT_AVAILABLE), SW_HIDE);
       }
       return TRUE;
index 552e0a6de66fefc32c4c987d5640c96e001cf268..d63f895879cd9dd858881ee9ac782afa57312cef 100644 (file)
@@ -131,6 +131,12 @@ static bool IsWlanAvailable()
    return true;
 }
 
+static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam)
+{
+   ShowWindow(hWnd, static_cast<int>(lParam));
+   return TRUE;
+}
+
 INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
 {
    switch (msg) {
@@ -163,13 +169,24 @@ INT_PTR CALLBACK Settings_WifiDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
                     ListBox_GetCount(hList) > 0);
 
       if (!IsWlanAvailable()) {
-         ShowWindow(GetDlgItem(hDlg, IDC_STATIC_WLAN_NOT_AVAILABLE), SW_SHOW);
+         // Set defaults
          Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLE_WIFI_MUTE), BST_UNCHECKED);
          Button_Enable(GetDlgItem(hDlg, IDC_ENABLE_WIFI_MUTE), FALSE);
          Button_SetCheck(GetDlgItem(hDlg, IDC_IS_PERMITLIST), BST_UNCHECKED);
          Button_Enable(GetDlgItem(hDlg, IDC_IS_PERMITLIST), FALSE);
-      }
-      else {
+
+         // Hide all child windows, except the notice
+         EnumChildWindows(hDlg, ShowChildWindow, SW_HIDE);
+
+         HWND hWifiNotAvail = GetDlgItem(hDlg, IDC_STATIC_WLAN_NOT_AVAILABLE);
+         RECT r;
+         GetClientRect(hWifiNotAvail, &r);
+         const int margin = 20;
+         SetWindowPos(
+            hWifiNotAvail, HWND_TOP,
+            margin, margin, r.right, r.bottom,
+            SWP_SHOWWINDOW);
+      } else {
          ShowWindow(GetDlgItem(hDlg, IDC_STATIC_WLAN_NOT_AVAILABLE), SW_HIDE);
       }
       return TRUE;
index 416039ed2a4661b1313970d7c18346579d3160d5..9bfd4df673d073daf3c0d1870cac35d0f42e228f 100644 (file)
@@ -122,7 +122,7 @@ void WifiDetector::CheckNetwork()
                   if (isMuteList_ && it != std::end(networks_)
                       || !isMuteList_ && it == std::end(networks_)) {
                      size_t profileNameLen = lstrlen(net->strProfileName);
-                     TCHAR* wiFiName = new TCHAR[profileNameLen + 1];
+                     wchar_t* wiFiName = new wchar_t[profileNameLen + 1];
                      StringCchCopy(wiFiName, profileNameLen + 1, net->strProfileName);
                      SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, 1,
                                  reinterpret_cast<LPARAM>(wiFiName));
@@ -153,7 +153,7 @@ void WifiDetector::WlanNotificationCallback(PWLAN_NOTIFICATION_DATA notifyData)
       if (isMuteList_ && it != std::end(networks_)
           || !isMuteList_ && it == std::end(networks_)) {
          size_t profileNameLen = lstrlen(wcnd->strProfileName);
-         TCHAR* wiFiName = new TCHAR[profileNameLen + 1];
+         wchar_t* wiFiName = new wchar_t[profileNameLen + 1];
          StringCchCopy(wiFiName, profileNameLen + 1, wcnd->strProfileName);
          SendMessage(hNotifyWnd_, WM_WIFISTATUSCHANGED, connected,
                       reinterpret_cast<LPARAM>(wiFiName));