quick blur demo: fix typo

And minor improvements to the win32 utils code.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-07-06 18:01:24 +08:00
parent 464e2af515
commit 01828e086f
4 changed files with 45 additions and 4 deletions

View File

@ -47,7 +47,7 @@ FramelessWindow {
if (!Settings.restoreGeometry(window)) {
FramelessHelper.moveWindowToDesktopCenter();
}
FramelessHelper.blurBehindWindow = true;
FramelessHelper.blurBehindWindowEnabled = true;
// Finally, show the window after everything is setted.
window.visible = true;
}

View File

@ -62,6 +62,7 @@ struct Win32UtilsHelper
Q_GLOBAL_STATIC(Win32UtilsHelper, g_utilsHelper)
static constexpr const wchar_t DUMMY_WINDOW_CLASS_NAME[] = L"FRAMELESSHELPER_DUMMY_WINDOW_CLASS";
static const QString qDwmRegistryKey = QString::fromWCharArray(kDwmRegistryKey);
static const QString qPersonalizeRegistryKey = QString::fromWCharArray(kPersonalizeRegistryKey);
static const QString qDwmColorKeyName = QString::fromWCharArray(kDwmColorKeyName);
@ -137,6 +138,9 @@ FRAMELESSHELPER_STRING_CONSTANT(GetDpiForSystem)
FRAMELESSHELPER_STRING_CONSTANT(DwmGetWindowAttribute)
FRAMELESSHELPER_STRING_CONSTANT(ntdll)
FRAMELESSHELPER_STRING_CONSTANT(RtlGetVersion)
FRAMELESSHELPER_STRING_CONSTANT(GetModuleHandleW)
FRAMELESSHELPER_STRING_CONSTANT(RegisterClassExW)
FRAMELESSHELPER_STRING_CONSTANT(CreateWindowExW)
template <typename T>
class HumbleComPtr
@ -193,6 +197,36 @@ private:
T *p = nullptr;
};
[[nodiscard]] static inline HWND ensureDummyWindow()
{
static const HWND hwnd = []() -> HWND {
const HMODULE instance = GetModuleHandleW(nullptr);
if (!instance) {
qWarning() << Utils::getSystemErrorMessage(kGetModuleHandleW);
return nullptr;
}
WNDCLASSEXW wcex;
SecureZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(wcex);
wcex.lpfnWndProc = DefWindowProcW;
wcex.hInstance = instance;
wcex.lpszClassName = DUMMY_WINDOW_CLASS_NAME;
const ATOM atom = RegisterClassExW(&wcex);
if (!atom) {
qWarning() << Utils::getSystemErrorMessage(kRegisterClassExW);
return nullptr;
}
const HWND window = CreateWindowExW(0, DUMMY_WINDOW_CLASS_NAME, nullptr,
WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, nullptr, nullptr, instance, nullptr);
if (!window) {
qWarning() << Utils::getSystemErrorMessage(kCreateWindowExW);
return nullptr;
}
return window;
}();
return hwnd;
}
[[nodiscard]] static inline bool doCompareWindowsVersion(const VersionNumber &targetOsVer)
{
static const std::optional<VersionNumber> currentOsVer = []() -> std::optional<VersionNumber> {
@ -797,7 +831,14 @@ bool Utils::isHighContrastModeEnabled()
quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
{
if (API_SHCORE_AVAILABLE(GetDpiForMonitor)) {
const HMONITOR monitor = MonitorFromPoint(POINT{50, 50}, MONITOR_DEFAULTTOPRIMARY);
const HMONITOR monitor = []() -> HMONITOR {
const HWND window = ensureDummyWindow();
if (window) {
return MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
}
static constexpr const int kTaskBarSize = 100;
return MonitorFromPoint(POINT{kTaskBarSize, kTaskBarSize}, MONITOR_DEFAULTTOPRIMARY);
}();
if (monitor) {
UINT dpiX = 0, dpiY = 0;
const HRESULT hr = API_CALL_FUNCTION(GetDpiForMonitor, monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);

View File

@ -181,7 +181,7 @@ void FramelessQuickHelperPrivate::attachToWindow()
// we reach here, and all the modifications from the Qt side will be lost
// due to QPA will reset the position and size of the window during it's
// initialization process.
QTimer::singleShot(0, this, [this](){
QTimer::singleShot(200, this, [this](){
if (FramelessConfig::instance()->isSet(Option::CenterWindowBeforeShow)) {
moveWindowToDesktopCenter();
}

View File

@ -304,7 +304,7 @@ void FramelessWidgetsHelperPrivate::attachToWindow()
// we reach here, and all the modifications from the Qt side will be lost
// due to QPA will reset the position and size of the window during it's
// initialization process.
QTimer::singleShot(0, this, [this](){
QTimer::singleShot(200, this, [this](){
if (FramelessConfig::instance()->isSet(Option::CenterWindowBeforeShow)) {
moveWindowToDesktopCenter();
}