From 3ede81c8ef863ed0fd9e12b3923ddc5e9c5f496f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20Steinh=C3=B6fer?= Date: Wed, 3 Aug 2022 09:31:45 +0200 Subject: [PATCH] Improved UI when WiFi/BT is not available. --- WinMute/Settings_BluetoothDlg.cpp | 23 ++++++++++++++++++++--- WinMute/Settings_WifiDlg.cpp | 23 ++++++++++++++++++++--- WinMute/WifiDetector.cpp | 4 ++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/WinMute/Settings_BluetoothDlg.cpp b/WinMute/Settings_BluetoothDlg.cpp index 854886d..eb9f6e3 100644 --- a/WinMute/Settings_BluetoothDlg.cpp +++ b/WinMute/Settings_BluetoothDlg.cpp @@ -169,6 +169,12 @@ static bool IsBluetoothAvailable() return true; } +static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam) +{ + ShowWindow(hWnd, static_cast(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; diff --git a/WinMute/Settings_WifiDlg.cpp b/WinMute/Settings_WifiDlg.cpp index 552e0a6..d63f895 100644 --- a/WinMute/Settings_WifiDlg.cpp +++ b/WinMute/Settings_WifiDlg.cpp @@ -131,6 +131,12 @@ static bool IsWlanAvailable() return true; } +static BOOL CALLBACK ShowChildWindow(HWND hWnd, LPARAM lParam) +{ + ShowWindow(hWnd, static_cast(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; diff --git a/WinMute/WifiDetector.cpp b/WinMute/WifiDetector.cpp index 416039e..9bfd4df 100644 --- a/WinMute/WifiDetector.cpp +++ b/WinMute/WifiDetector.cpp @@ -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(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(wiFiName)); -- 2.43.0