Minor tweaks
1. Fix compilation error for QMake. 2. Fix some warning messages are in the wrong place. 3. Fix the IActiveDesktop can't get wallpaper. 4. Other minor tweaks. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
43d0e5f95d
commit
399b1cef1c
2
lib.pro
2
lib.pro
|
@ -50,6 +50,6 @@ win32 {
|
||||||
utilities_win32.cpp \
|
utilities_win32.cpp \
|
||||||
framelesshelper_win32.cpp \
|
framelesshelper_win32.cpp \
|
||||||
qtacryliceffecthelper_win32.cpp
|
qtacryliceffecthelper_win32.cpp
|
||||||
LIBS += -luser32 -lshell32 -lgdi32 -ldwmapi
|
LIBS += -luser32 -lshell32 -lgdi32 -ldwmapi -lole32
|
||||||
RC_FILE = framelesshelper.rc
|
RC_FILE = framelesshelper.rc
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,7 +220,7 @@ bool Utilities::isDwmBlurAvailable()
|
||||||
qWarning() << "DwmIsCompositionEnabled failed.";
|
qWarning() << "DwmIsCompositionEnabled failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isWin7OrGreater() && (enabled == TRUE);
|
return isWin7OrGreater() && (enabled != FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue)
|
int Utilities::getSystemMetric(const QWindow *window, const SystemMetric metric, const bool dpiAware, const bool forceSystemValue)
|
||||||
|
@ -338,7 +338,7 @@ bool Utilities::setBlurEffectEnabled(const QWindow *window, const bool enabled,
|
||||||
} else {
|
} else {
|
||||||
accentPolicy.AccentState = ACCENT_DISABLED;
|
accentPolicy.AccentState = ACCENT_DISABLED;
|
||||||
}
|
}
|
||||||
result = win32Data()->SetWindowCompositionAttributePFN(hwnd, &wcaData) == TRUE;
|
result = (win32Data()->SetWindowCompositionAttributePFN(hwnd, &wcaData) != FALSE);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qWarning() << "SetWindowCompositionAttribute failed.";
|
qWarning() << "SetWindowCompositionAttribute failed.";
|
||||||
}
|
}
|
||||||
|
@ -365,6 +365,7 @@ bool Utilities::isColorizationEnabled()
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWin10OrGreater()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// TODO: Is there an official Win32 API to do this?
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const QSettings registry(g_dwmRegistryKey, QSettings::NativeFormat);
|
const QSettings registry(g_dwmRegistryKey, QSettings::NativeFormat);
|
||||||
const bool colorPrevalence = registry.value(QStringLiteral("ColorPrevalence"), 0).toULongLong(&ok) != 0;
|
const bool colorPrevalence = registry.value(QStringLiteral("ColorPrevalence"), 0).toULongLong(&ok) != 0;
|
||||||
|
@ -447,6 +448,7 @@ bool Utilities::isTransparencyEffectEnabled()
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWin10OrGreater()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// TODO: Is there an official Win32 API to do this?
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const QSettings registry(g_personalizeRegistryKey, QSettings::NativeFormat);
|
const QSettings registry(g_personalizeRegistryKey, QSettings::NativeFormat);
|
||||||
const bool transparencyEnabled = registry.value(QStringLiteral("EnableTransparency"), 0).toULongLong(&ok) != 0;
|
const bool transparencyEnabled = registry.value(QStringLiteral("EnableTransparency"), 0).toULongLong(&ok) != 0;
|
||||||
|
@ -499,6 +501,7 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
// TODO: Why CLSCTX_INPROC_SERVER failed?
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
||||||
UINT monitorCount = 0;
|
UINT monitorCount = 0;
|
||||||
if (SUCCEEDED(pDesktopWallpaper->GetMonitorDevicePathCount(&monitorCount))) {
|
if (SUCCEEDED(pDesktopWallpaper->GetMonitorDevicePathCount(&monitorCount))) {
|
||||||
|
@ -527,8 +530,8 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to initialize COM.";
|
qWarning() << "Failed to initialize COM.";
|
||||||
}
|
}
|
||||||
|
qDebug() << "The IDesktopWallpaper interface failed. Trying the IActiveDesktop interface instead.";
|
||||||
}
|
}
|
||||||
qDebug() << "The IDesktopWallpaper interface failed. Trying the IActiveDesktop interface instead.";
|
|
||||||
if (SUCCEEDED(CoInitialize(nullptr))) {
|
if (SUCCEEDED(CoInitialize(nullptr))) {
|
||||||
IActiveDesktop *pActiveDesktop = nullptr;
|
IActiveDesktop *pActiveDesktop = nullptr;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||||
|
@ -540,9 +543,9 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_ActiveDesktop, nullptr, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, reinterpret_cast<void **>(&pActiveDesktop))) && pActiveDesktop) {
|
if (SUCCEEDED(CoCreateInstance(CLSID_ActiveDesktop, nullptr, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, reinterpret_cast<void **>(&pActiveDesktop))) && pActiveDesktop) {
|
||||||
PWSTR wallpaperPath = nullptr;
|
WCHAR wallpaperPath[MAX_PATH] = {};
|
||||||
// AD_GETWP_BMP, AD_GETWP_IMAGE ???
|
// TODO: AD_GETWP_BMP, AD_GETWP_IMAGE, AD_GETWP_LAST_APPLIED. What's the difference?
|
||||||
if (SUCCEEDED(pActiveDesktop->GetWallpaper(wallpaperPath, MAX_PATH, AD_GETWP_LAST_APPLIED)) && wallpaperPath) {
|
if (SUCCEEDED(pActiveDesktop->GetWallpaper(wallpaperPath, MAX_PATH, AD_GETWP_LAST_APPLIED))) {
|
||||||
return QImage(QString::fromWCharArray(wallpaperPath));
|
return QImage(QString::fromWCharArray(wallpaperPath));
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "IActiveDesktop::GetWallpaper() failed.";
|
qWarning() << "IActiveDesktop::GetWallpaper() failed.";
|
||||||
|
@ -555,7 +558,7 @@ QImage Utilities::getDesktopWallpaperImage(const int screen)
|
||||||
}
|
}
|
||||||
qDebug() << "Shell API failed. Using SystemParametersInfoW instead.";
|
qDebug() << "Shell API failed. Using SystemParametersInfoW instead.";
|
||||||
LPWSTR wallpaperPath = nullptr;
|
LPWSTR wallpaperPath = nullptr;
|
||||||
if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) == TRUE) {
|
if (SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaperPath, 0) != FALSE) {
|
||||||
return QImage(QString::fromWCharArray(wallpaperPath));
|
return QImage(QString::fromWCharArray(wallpaperPath));
|
||||||
}
|
}
|
||||||
qWarning() << "SystemParametersInfoW failed. Reading from the registry instead.";
|
qWarning() << "SystemParametersInfoW failed. Reading from the registry instead.";
|
||||||
|
@ -582,6 +585,7 @@ QColor Utilities::getDesktopBackgroundColor(const int screen)
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
// TODO: Why CLSCTX_INPROC_SERVER failed?
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
||||||
COLORREF color = 0;
|
COLORREF color = 0;
|
||||||
if (SUCCEEDED(pDesktopWallpaper->GetBackgroundColor(&color))) {
|
if (SUCCEEDED(pDesktopWallpaper->GetBackgroundColor(&color))) {
|
||||||
|
@ -595,8 +599,10 @@ QColor Utilities::getDesktopBackgroundColor(const int screen)
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to initialize COM.";
|
qWarning() << "Failed to initialize COM.";
|
||||||
}
|
}
|
||||||
|
qDebug() << "The IDesktopWallpaper interface failed.";
|
||||||
}
|
}
|
||||||
qDebug() << "The IDesktopWallpaper interface failed.";
|
// TODO: Is there any other way to get the background color? Traditional Win32 API? Registry?
|
||||||
|
// Is there a Shell API for Win7?
|
||||||
return Qt::black;
|
return Qt::black;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,6 +620,7 @@ Utilities::DesktopWallpaperAspectStyle Utilities::getDesktopWallpaperAspectStyle
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
|
// TODO: Why CLSCTX_INPROC_SERVER failed?
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
if (SUCCEEDED(CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_LOCAL_SERVER, IID_IDesktopWallpaper, reinterpret_cast<void **>(&pDesktopWallpaper))) && pDesktopWallpaper) {
|
||||||
DESKTOP_WALLPAPER_POSITION position = DWPOS_FILL;
|
DESKTOP_WALLPAPER_POSITION position = DWPOS_FILL;
|
||||||
if (SUCCEEDED(pDesktopWallpaper->GetPosition(&position))) {
|
if (SUCCEEDED(pDesktopWallpaper->GetPosition(&position))) {
|
||||||
|
@ -640,8 +647,8 @@ Utilities::DesktopWallpaperAspectStyle Utilities::getDesktopWallpaperAspectStyle
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to initialize COM.";
|
qWarning() << "Failed to initialize COM.";
|
||||||
}
|
}
|
||||||
|
qDebug() << "The IDesktopWallpaper interface failed. Trying the IActiveDesktop interface instead.";
|
||||||
}
|
}
|
||||||
qDebug() << "The IDesktopWallpaper interface failed. Trying the IActiveDesktop interface instead.";
|
|
||||||
if (SUCCEEDED(CoInitialize(nullptr))) {
|
if (SUCCEEDED(CoInitialize(nullptr))) {
|
||||||
IActiveDesktop *pActiveDesktop = nullptr;
|
IActiveDesktop *pActiveDesktop = nullptr;
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||||
|
@ -743,7 +750,8 @@ quint32 Utilities::getWindowDpi(const QWindow *window)
|
||||||
qWarning() << "MonitorFromWindow failed.";
|
qWarning() << "MonitorFromWindow failed.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Using Direct2D to get DPI is deprecated.
|
// We can use Direct2D to get DPI since Win7 or Vista, but it's marked as deprecated by Microsoft
|
||||||
|
// in the latest SDK and we'll get compilation warnings because of that, so we just don't use it here.
|
||||||
const HDC hdc = GetDC(nullptr);
|
const HDC hdc = GetDC(nullptr);
|
||||||
if (hdc) {
|
if (hdc) {
|
||||||
const int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
|
const int dpiX = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||||
|
|
Loading…
Reference in New Issue