Skip to content

Commit

Permalink
check if the OS is Windows 11
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Feb 12, 2024
1 parent ffc2b62 commit 9e88b78
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions include/fluent_tray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

#include <windows.h>

#if defined(_MSC_VER) && _MSC_VER >= 1500
#pragma warning(disable : 4005)
#include <ntstatus.h>
#pragma warning(default : 4005)
#endif

#include <dwmapi.h>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down Expand Up @@ -792,13 +798,41 @@ namespace fluent_tray

// Set rounded window for Windows 11 only.
if(round_corner) {
auto pref = DWMWCP_ROUND ;
if(DwmSetWindowAttribute(
hwnd_,
DWMWA_WINDOW_CORNER_PREFERENCE,
&pref, sizeof(pref)) != S_OK) {
using RtlGetVersionType = NTSTATUS (WINAPI*)(PRTL_OSVERSIONINFOW) ;
const auto hmodule = LoadLibraryW(L"ntdll.dll") ;
if(!hmodule) {
return false ;
}

// cast to void* once to avoid warnings about type conversion.
const auto RtlGetVersion = reinterpret_cast<RtlGetVersionType>(
reinterpret_cast<void*>(GetProcAddress(hmodule, "RtlGetVersion"))) ;
if(!RtlGetVersion) {
FreeLibrary(hmodule) ;
return false ;
}

OSVERSIONINFOW vinfo ;
vinfo.dwOSVersionInfoSize = sizeof(decltype(vinfo)) ;
auto result = RtlGetVersion(&vinfo) ;
if(!FreeLibrary(hmodule)) {
return false ;
}

if(result != STATUS_SUCCESS) {
return false ;
}

// Check if the OS is Windows11
if(vinfo.dwBuildNumber >= 22000) {
auto pref = DWMWCP_ROUND ;
if(DwmSetWindowAttribute(
hwnd_,
DWMWA_WINDOW_CORNER_PREFERENCE,
&pref, sizeof(pref)) != S_OK) {
return false ;
}
}
}

if(!change_icon(icon_path)) {
Expand Down

0 comments on commit 9e88b78

Please sign in to comment.