Skip to content

Commit

Permalink
Update to VS2022, tweaks for Windows 11 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ozone10 committed Jun 13, 2022
1 parent a7611e9 commit aa9ca5d
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 32 deletions.
Binary file modified Plugin/Plugin.rc
Binary file not shown.
24 changes: 17 additions & 7 deletions Plugin/PluginDarkContextMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 oZone
Copyright (C) 2019-2022 oZone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -21,15 +21,17 @@
// have been commented out. Uncomment any functions as needed.
// For more information, see the SDK docs: https://docs.rainmeter.net/developers/plugin/cpp/

static bool isWin11 = false;

inline bool IsAtLeastWin10Build(DWORD buildNumber)
{
if (!IsWindows10OrGreater()) {
return false;
}

auto mask = VerSetConditionMask(0, VER_BUILDNUMBER, VER_GREATER_EQUAL);
const auto mask = VerSetConditionMask(0, VER_BUILDNUMBER, VER_GREATER_EQUAL);

OSVERSIONINFOEXW osvi;
OSVERSIONINFOEXW osvi{};
osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwBuildNumber = buildNumber;
return VerifyVersionInfo(&osvi, VER_BUILDNUMBER, mask) != FALSE;
Expand All @@ -38,7 +40,7 @@ inline bool IsAtLeastWin10Build(DWORD buildNumber)
void SetDarkMode(struct Measure* skin, HMODULE hUxtheme)
{
const auto ord135 = GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
auto useDarkMode = skin->mode;
const auto useDarkMode = skin->mode;

if (IsAtLeastWin10Build(VER_1903)) {
using SPAM = PreferredAppMode (WINAPI*)(PreferredAppMode appMode);
Expand All @@ -63,6 +65,11 @@ void SetDarkMode(struct Measure* skin, HMODULE hUxtheme)
_AllowDarkModeForApp(useDarkMode);
}
}

if (isWin11) {
const auto useWin11DarkMode = static_cast<BOOL>(useDarkMode);
DwmSetWindowAttribute(skin->hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &useWin11DarkMode, sizeof(BOOL));
}
}

void SetTheme(struct Measure* measure)
Expand Down Expand Up @@ -104,11 +111,11 @@ void GetTooltips(struct Measure* measure)
GetWindowThreadProcessId(hTooltip, &checkProcessID);

if (checkProcessID == measure->ownerProcessID) {
WCHAR className[64] = { 0 };
WCHAR className[64] = {'\0'};

if (GetWindow(hTooltip, GW_OWNER) == measure->hWnd
&& GetClassName(hTooltip, className, _countof(className)) > 0
&& wcscmp(className, TOOLTIPS_CLASS) == 0)
&& GetClassName(hTooltip, &className[0], _countof(className)) > 0
&& wcscmp(&className[0], TOOLTIPS_CLASS) == 0)
{
measure->hTips.push_back(hTooltip);
measure->countTips += 1;
Expand Down Expand Up @@ -140,6 +147,8 @@ PLUGIN_EXPORT void Initialize(void** data, void* rm)
return;
}

isWin11 = IsAtLeastWin10Build(BUILD_WIN11);

measure->validVer = true;
measure->hWnd = RmGetSkinWindow(rm);
measure->mode = RmReadInt(rm, L"DarkMode", 0) > 0;
Expand Down Expand Up @@ -228,4 +237,5 @@ PLUGIN_EXPORT void Finalize(void* data)
SetTheme(measure);
}
delete measure;
measure = nullptr;
}
8 changes: 5 additions & 3 deletions Plugin/PluginDarkContextMenu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 oZone
Copyright (C) 2019-2022 oZone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -16,8 +16,10 @@

#pragma once

const DWORD VER_1809 = 17763; // Windows 10 1809 (October 2018 Update)
const DWORD VER_1903 = 18362; // Windows 10 1903 (May 2019 Update)
constexpr DWORD VER_1809 = 17763; // Windows 10 1809 (October 2018 Update)
constexpr DWORD VER_1903 = 18362; // Windows 10 1903 (May 2019 Update)

constexpr DWORD BUILD_WIN11 = 22000; // Windows 11 first "stable" build

struct Measure {
HWND hWnd = nullptr;
Expand Down
12 changes: 6 additions & 6 deletions Plugin/PluginDarkContextMenu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,32 @@
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMD|Win32'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseMD|x64'">
<Link>
<AdditionalDependencies>uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>Dwmapi.lib;uxtheme.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Plugin/StdAfx.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 oZone
Copyright (C) 2019-2022 oZone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand Down
3 changes: 2 additions & 1 deletion Plugin/StdAfx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2019-2020 oZone
Copyright (C) 2019-2022 oZone
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -22,6 +22,7 @@
// WinAPI
#include <Windows.h>

#include <dwmapi.h>
#include <Uxtheme.h>
#include <VersionHelpers.h>

Expand Down
12 changes: 6 additions & 6 deletions Plugin/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Has to be the same as the project name!
#define VER_PLUGIN_NAME_STR "DarkContextMenu"
#define VER_PLUGIN_MAJOR 1
#define VER_PLUGIN_MINOR 1
#define VER_PLUGIN_REVISION 3
#define VER_PLUGIN_MINOR 2
#define VER_PLUGIN_REVISION 0
#define VER_PLUGIN_BUILD 0
#define VER_PLUGIN_AUTHOR_STR "oZone"
#define VER_PLUGIN_YEAR 2020
#define VER_PLUGIN_YEAR 2022
#define VER_RAINMETER_MAJOR 4
#define VER_RAINMETER_MINOR 4
#define VER_RAINMETER_REVISION 0
#define VER_RAINMETER_BUILD 3348
#define VER_RAINMETER_MINOR 5
#define VER_RAINMETER_REVISION 13
#define VER_RAINMETER_BUILD 3632
// This is the path relative to root directory (where build.bat is placed)
//#define EXAMPLE_SKIN_PATH "ExampleSkin"
//#define EXAMPLE_SKIN_NAME "Example Skin"
2 changes: 1 addition & 1 deletion VS/RainmeterPlugin.Cpp.Default.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<TargetName>$(ProjectName)</TargetName>
<ConfigurationType>DynamicLibrary</ConfigurationType>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<SpectreMitigation>Spectre</SpectreMitigation>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions VS/RainmeterPlugin.Cpp.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<ItemDefinitionGroup Label="Globals">
<ClCompile>
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
<LanguageStandard>stdcpp17</LanguageStandard>
<WarningLevel>Level3</WarningLevel>
<LanguageStandard>stdcpp20</LanguageStandard>
<WarningLevel>Level4</WarningLevel>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessorDefinitions>WIN32;_WINDOWS;_USRDLL;STRICT_TYPED_ITEMIDS;NOMINMAX;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;SUPPORT_UTF8;%(PreprocessorDefinitions);PROJECT_NAME="$(ProjectName)"</PreprocessorDefinitions>
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 1.1.3.{build}
version: 1.2.0.{build}

branches:
only:
- master

skip_tags: true

image: Visual Studio 2019
image: Visual Studio 2022
configuration: Release

clone_depth: 1
Expand Down
6 changes: 3 additions & 3 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
@echo Choose Visual Studio 2019 Edition (after 5s will default to (2) Enterprise):
@echo Choose Visual Studio 2022 Edition (after 5s will default to (2) Enterprise):
::https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners#visual-studio-2019-enterprise
::This is because I am poor.
:Reset
Expand All @@ -17,7 +17,7 @@ goto Continue
set Edition=Community
goto Continue
:Continue
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\%Edition%\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
call "C:\Program Files\Microsoft Visual Studio\2022\%Edition%\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
set solutionsFile=".\SDK-CPP.sln"
msbuild -m /t:build /p:Configuration=Release;Platform=x64 %solutionsFile%
msbuild -m /t:build /p:Configuration=Release;Platform=Win32 %solutionsFile%
msbuild -m /t:build /p:Configuration=Release;Platform=Win32 %solutionsFile%

0 comments on commit aa9ca5d

Please sign in to comment.