From 05a829f923a88e69b2ceaa372820a2dcb8c083cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 27 Sep 2019 13:36:38 +0200 Subject: Win32: Consolidate registry code Add a RAII class for registry keys and use it throughout the code base. Change-Id: I666b2fbb790f83436443101d6bc1e3c0525e78df Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/windows/qwindowscontext.cpp | 26 ++++++----------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp') diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index bb349f08a7..f7d04b667d 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -1518,28 +1519,13 @@ QTouchDevice *QWindowsContext::touchDevice() const d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); } -static DWORD readDwordRegistrySetting(const wchar_t *regKey, const wchar_t *subKey, DWORD defaultValue) -{ - DWORD result = defaultValue; - HKEY handle; - if (RegOpenKeyEx(HKEY_CURRENT_USER, regKey, 0, KEY_READ, &handle) == ERROR_SUCCESS) { - DWORD type; - if (RegQueryValueEx(handle, subKey, nullptr, &type, nullptr, nullptr) == ERROR_SUCCESS - && type == REG_DWORD) { - DWORD value; - DWORD size = sizeof(result); - if (RegQueryValueEx(handle, subKey, nullptr, nullptr, reinterpret_cast(&value), &size) == ERROR_SUCCESS) - result = value; - } - RegCloseKey(handle); - } - return result; -} - DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) { - return readDwordRegistrySetting(L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", - subKey, defaultValue); + const auto value = + QWinRegistryKey(HKEY_CURRENT_USER, + LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)") + .dwordValue(subKey); + return value.second ? value.first : defaultValue; } static inline bool isEmptyRect(const RECT &rect) -- cgit v1.2.3