Просмотр исходного кода

UI: Add funcs to get windows ver. and disable aero

Adds two functions, GetWindowsVersion and SetAeroEnabled.
jp9000 10 лет назад
Родитель
Сommit
0c631db046
2 измененных файлов с 49 добавлено и 0 удалено
  1. 44 0
      obs/platform-windows.cpp
  2. 5 0
      obs/platform.hpp

+ 44 - 0
obs/platform-windows.cpp

@@ -28,6 +28,7 @@ using namespace std;
 #include <windows.h>
 #include <shellapi.h>
 #include <shlobj.h>
+#include <Dwmapi.h>
 
 static inline bool check_path(const char* data, const char *path,
 		string &output)
@@ -159,3 +160,46 @@ vector<string> GetPreferredLocales()
 
 	return result;
 }
+
+uint32_t GetWindowsVersion()
+{
+	static uint32_t ver = 0;
+
+	if (ver == 0) {
+		OSVERSIONINFOW osvi = {};
+		osvi.dwOSVersionInfoSize = sizeof(osvi);
+
+		if (GetVersionExW(&osvi)) {
+			ver = osvi.dwMajorVersion << 8 | osvi.dwMinorVersion;
+		}
+	}
+
+	return ver;
+}
+
+void SetAeroEnabled(bool enable)
+{
+	static HRESULT (WINAPI *func)(UINT) = nullptr;
+	static bool failed = false;
+
+	if (!func) {
+		if (failed) {
+			return;
+		}
+
+		HMODULE dwm = LoadLibraryW(L"dwmapi");
+		if (!dwm) {
+			failed = true;
+			return;
+		}
+
+		func = reinterpret_cast<decltype(func)>(GetProcAddress(dwm,
+						"DwmEnableComposition"));
+		if (!func) {
+			failed = true;
+			return;
+		}
+	}
+
+	func(enable ? DWM_EC_ENABLECOMPOSITION : DWM_EC_DISABLECOMPOSITION);
+}

+ 5 - 0
obs/platform.hpp

@@ -42,3 +42,8 @@ bool InitApplicationBundle();
 std::string GetDefaultVideoSavePath();
 
 std::vector<std::string> GetPreferredLocales();
+
+#ifdef _WIN32
+uint32_t GetWindowsVersion();
+void SetAeroEnabled(bool enable);
+#endif