/** * FileName: Common.h * * Copyright (C) 2024 Maplespe * * This file is part of MToolBox and DWMBlurGlass. * DWMBlurGlass is free software: you can redistribute it and/or modify it under the terms of the * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 * of the License, or any later version. * * DWMBlurGlass is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with Foobar. * If not, see . */ #pragma once #include #include EXTERN_C IMAGE_DOS_HEADER __ImageBase; namespace MDWMBlurGlass { extern const HINSTANCE this_inst; enum class blurMethod { CustomBlur, AccentBlur, DWMAPIBlur }; enum class effectType { None = -1, Blur, Aero, Acrylic, Mica }; enum class blurQuality { Speed = 0, Quality = 1 }; struct ConfigData { bool applyglobal = false; bool extendBorder = false; bool reflection = false; bool oldBtnHeight = false; bool customAmount = false; bool useAccentColor = false; bool crossFade = true; bool overrideAccent = false; bool powerSavingMode = false; bool disableOnBattery = true; bool scaleOptimizer = false; bool titlebtnGlow = false; bool disableFramerateLimit = false; bool customAeroTexture = false; bool autoDownloadSymbols = true; bool customTitleBtnSize = false; //Options without GUI int extendRound = 10; int clipRound = 0; int titlebtnOffsetX = -1; // int customCloseBtnW = 49; int customMaxBtnW = 27; int customMinBtnW = 29; int customBtnFrameH = 20; float blurAmount = 20.f; float customBlurAmount = 20.f; float luminosityOpacity = 0.65f; float glassIntensity = 1.f; UINT crossfadeTime = 160; // these settings are optimal for the default Sky color from Windows 7 // newly added params since 2.1.0 float aeroColorBalance = 0.08f; float aeroAfterglowBalance = 0.43f; float aeroBlurBalance = 0.49f; COLORREF activeTextColor = 0xFF000000; COLORREF inactiveTextColor = 0xFFB4B4B4; COLORREF activeBlendColor = 0x64FFFFFF; COLORREF inactiveBlendColor = 0x64FFFFFF; COLORREF activeTextColorDark = 0xFFFFFFFF; COLORREF inactiveTextColorDark = 0xFFB4B4B4; COLORREF activeBlendColorDark = 0x64000000; COLORREF inactiveBlendColorDark = 0x64000000; blurMethod blurmethod = blurMethod::CustomBlur; effectType effectType = effectType::Blur; blurQuality blurQuality = blurQuality::Speed; std::wstring customAeroTexturePath; bool isDefault() { static ConfigData _default; return memcmp(this, &_default, sizeof ConfigData) == 0; } static ConfigData LoadFromFile(std::wstring_view path); }; enum class MHostNotifyType { Refresh, Shutdown, EnableTransparency }; enum class MClientNotifyType { Shutdown = 1, QueryTransparency }; enum MHostModuleType { dwmcore, udwm }; auto constexpr DWMBlurGlassNotifyClassName = L"MDWMBlurGlassExtNotify"; auto constexpr DWMBlurGlassHostNotifyClassName = L"MDWMBlurGlassHostNotify"; namespace RAIIHelper { template class lambda_call { public: lambda_call(const lambda_call&) = delete; lambda_call& operator=(const lambda_call&) = delete; lambda_call& operator=(lambda_call&& other) = delete; inline explicit lambda_call(TLambda&& lambda) noexcept : m_lambda(std::move(lambda)) { static_assert(std::is_same::value, "scope_exit的lambda函数一定不能有返回值"); static_assert(!std::is_lvalue_reference::value && !std::is_rvalue_reference::value, "scope_exit只能直接与lambda函数一起使用"); } inline lambda_call(lambda_call&& other) noexcept : m_lambda(std::move(other.m_lambda)), m_call(other.m_call) { other.m_call = false; } inline ~lambda_call() noexcept { reset(); } // 确保scope_exit lambda不会被调用 inline void release() noexcept { m_call = false; } // 立刻执行scope_exit lambda如果还没有运行的话;确保它不再次运行 inline void reset() noexcept { if (m_call) { m_call = false; m_lambda(); } } // 返回true如果scope_exit lambda仍要被执行 [[nodiscard]] inline explicit operator bool() const noexcept { return m_call; } protected: TLambda m_lambda; bool m_call = true; }; /* 返回一个对象,该对象在销毁时执行给定的lambda函数,请使用auto捕获返回的对象 使用reset()提前执行lambda或使用release()避免执行 在lambda中抛出的异常将引发快速失败 你可以认为这个对象的作用跟finally差不多 */ template [[nodiscard]] inline auto scope_exit(TLambda&& lambda) noexcept { return lambda_call(std::forward(lambda)); } } namespace Utils { extern std::wstring GetCurrentDir(); extern std::wstring GetIniString(std::wstring_view path, std::wstring_view appName, std::wstring_view keyName); extern bool IsAppUseLightMode(); } }