0

Some of the DWMWINDOWATTRIBUTE options in the Windows SDK are only available starting with certain Windows builds, for example:

DWMWA_BORDER_COLOR

This value is supported starting with Windows 11 Build 22000.

How can I check for the build version using the preprocessor? Something like:

#if WINDOWS_BUILD >= 22000
COLORREF hexCol = 0x00505050;
DwmSetWindowAttribute(GetWin32Handle(), DWMWINDOWATTRIBUTE::DWMWA_BORDER_COLOR, &hexCol, sizeof(hexCol));
#endif

I know about the WINVER macro, but that can only be used to check the main Windows version, and not a specific build. The possible values also only appear to go up to Windows 10, so you can't even use it to check for Windows 11:

#define _WIN32_WINNT_NT4                    0x0400
#define _WIN32_WINNT_WIN2K                  0x0500
#define _WIN32_WINNT_WINXP                  0x0501
#define _WIN32_WINNT_WS03                   0x0502
#define _WIN32_WINNT_WIN6                   0x0600
#define _WIN32_WINNT_VISTA                  0x0600
#define _WIN32_WINNT_WS08                   0x0600
#define _WIN32_WINNT_LONGHORN               0x0600
#define _WIN32_WINNT_WIN7                   0x0601
#define _WIN32_WINNT_WIN8                   0x0602
#define _WIN32_WINNT_WINBLUE                0x0603
#define _WIN32_WINNT_WINTHRESHOLD           0x0A00
#define _WIN32_WINNT_WIN10                  0x0A00

If I can't check against the build version, is there some other way I can check whether DWMWA_BORDER_COLOR is defined? I can't use #ifdef, since it's an enum value and not a macro.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Silverlan
  • 2,783
  • 3
  • 31
  • 66
  • 5
    I've some doubts whether a preprocessor condition is the right tool for your issue. It would be evaluated at compile time (i.e. when you compile your software). Shouldn't the check happen at run-time (when and where your executable is running)? – Scheff's Cat Apr 12 '23 at 05:46
  • FYI: [Getting OS build version from Win32 Api C++](https://stackoverflow.com/q/47581146/7478597), [Detecting Windows 10 version](https://stackoverflow.com/q/36543301/7478597) – Scheff's Cat Apr 12 '23 at 06:01
  • The problem is that the enum value doesn't exist for older SDK versions, so trying to compile it would just end with a compile error. – Silverlan Apr 12 '23 at 06:46
  • 1
    It's quite simple to require a certain SDK version to compile your source code. This could be just a sentence in the doc. or README. Nevertheless, the problem at runtime would persist... – Scheff's Cat Apr 12 '23 at 06:59
  • *"The problem is that the enum value doesn't exist for older SDK versions, so trying to compile it would just end with a compile error."* - Sure. It's *always* been like that. The solution? Always keep your SDK up to date. Having a minimum required SDK is normal. That said, don't write code based on the system's version. Instead, either query for the system's capabilities, or, if that is not available, unconditionally call the API and respond to its outcome. – IInspectable Apr 12 '23 at 07:10
  • I assume that, since they specifically call it "Windows 11 Build 22000", the SDK version is only available on Windows 11. I don't want to force people to switch over to a newer OS to build the project just for a minor aesthetic feature. – Silverlan Apr 12 '23 at 07:19
  • 2
    The [latest Windows SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/) is supported for Windows 10 1507 or higher. You don't need to run the compiler on your target version. You can compile Windows 11 exclusive code on Windows 10 just fine (and probably on pretty much any version before that, too). – IInspectable Apr 12 '23 at 07:40
  • 1
    The SDK is just a set of declarations and such. You can use newer SDKs in compilers running on older OSes. You can either 1) setup your project to *target* Windows 11 build 22000 as a minimum, and then use `DWMWA_BORDER_COLOR` *unconditionally* in the API call, or else 2) setup your project to *target* an older OS version, and then use a *runtime* check to get the OS version and then use `DWMWA_BORDER_COLOR` in the API call only if your app is *running* on Windows 11 build 22000 or later. – Remy Lebeau Apr 12 '23 at 19:27

1 Answers1

1

Windows 11 still uses the Windows 10 version number as well. At least for now, OS build number 22000 is the standard that distinguishes Windows 10 from Windows 11.

As far as I'm concerned, It's the reason that you couldn't use it to check Windows 11.

" the SDK version is only available on Windows 11. I don't want to force people to switch over to a newer OS to build the project just for a minor aesthetic feature." It your system is Windows 10 version 1507 or higher, you could try to install The Windows SDK (10.0.22000.0) or higher for Windows 11. And then you could set the Windows SDK explicitly in your project properties.

enter image description here

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20