diff --git a/src/modules/fancyzones/FancyZonesLib/WindowDrag.cpp b/src/modules/fancyzones/FancyZonesLib/WindowDrag.cpp index c5c18d9fae..25de2dbb1a 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowDrag.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowDrag.cpp @@ -213,22 +213,30 @@ void WindowDrag::SetWindowTransparency() if (!SetLayeredWindowAttributes(m_window, 0, (255 * 50) / 100, LWA_ALPHA)) { Logger::error(L"Window transparency: SetLayeredWindowAttributes failed, {}", get_last_error_or_default(GetLastError())); + return; } + + m_windowProperties.transparencySet = true; } } void WindowDrag::ResetWindowTransparency() { - if (FancyZonesSettings::settings().makeDraggedWindowTransparent) + if (FancyZonesSettings::settings().makeDraggedWindowTransparent && m_windowProperties.transparencySet) { + bool reset = true; if (!SetLayeredWindowAttributes(m_window, m_windowProperties.crKey, m_windowProperties.alpha, m_windowProperties.dwFlags)) { - Logger::error(L"Window transparency: SetLayeredWindowAttributes failed"); + Logger::error(L"Window transparency: SetLayeredWindowAttributes failed, {}", get_last_error_or_default(GetLastError())); + reset = false; } if (SetWindowLong(m_window, GWL_EXSTYLE, m_windowProperties.exstyle) == 0) { Logger::error(L"Window transparency: SetWindowLong failed, {}", get_last_error_or_default(GetLastError())); + reset = false; } + + m_windowProperties.transparencySet = !reset; } } diff --git a/src/modules/fancyzones/FancyZonesLib/WindowDrag.h b/src/modules/fancyzones/FancyZonesLib/WindowDrag.h index f45dc313f8..0956af9841 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowDrag.h +++ b/src/modules/fancyzones/FancyZonesLib/WindowDrag.h @@ -33,6 +33,7 @@ private: COLORREF crKey = RGB(0, 0, 0); DWORD dwFlags = 0; BYTE alpha = 0; + bool transparencySet{false}; }; const HWND m_window;