Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dark-menus.wh.cpp #1309

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions mods/dark-menus.wh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// ==WindhawkMod==
// @id dark-menus
// @name Dark mode context menus
// @description Enables dark mode for all win32 menus.
// @version 1.0
// @author Mgg Sk
// @github https://github.com/MGGSK
// @include *
// ==/WindhawkMod==

// ==WindhawkModReadme==
/*
# Dark mode context menus
Forces dark mode for all win32 context menus to create a more consistent UI.

### Before:
![Before](https://i.imgur.com/bGRVJz8.png)

### After:
![After](https://i.imgur.com/BURKEki.png)
*/
m417z marked this conversation as resolved.
Show resolved Hide resolved
// ==/WindhawkModReadme==

#include <minwindef.h>
#include <winerror.h>

enum AppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
};

using FlushMenuThemes_T = void (WINAPI *)();
using SetPreferredAppMode_T = HRESULT (WINAPI *)(AppMode appMode);

FlushMenuThemes_T FlushMenuThemes;
SetPreferredAppMode_T SetPreferredAppMode;

//Applies the theme to all menus.
HRESULT ApplyTheme()
{
FlushMenuThemes();
m417z marked this conversation as resolved.
Show resolved Hide resolved
return SetPreferredAppMode(ForceDark);
}

//Import functions
BOOL Wh_ModInit() {
HMODULE hUxtheme = LoadLibraryExW(L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
FARPROC pSetPreferredAppMode = GetProcAddress(hUxtheme, MAKEINTRESOURCEA(135));
FARPROC pFlushMenuThemes = GetProcAddress(hUxtheme, MAKEINTRESOURCEA(136));

SetPreferredAppMode = reinterpret_cast<SetPreferredAppMode_T>(pSetPreferredAppMode);
FlushMenuThemes = reinterpret_cast<FlushMenuThemes_T>(pFlushMenuThemes);

HRESULT hResult = ApplyTheme();
return SUCCEEDED(hResult);
}

//Restores the default theme.
void Wh_ModUninit()
{
FlushMenuThemes();
SetPreferredAppMode(Default);
}
Loading