From 8d3281e2e9581772fd11fb12d576921e9ffef2e3 Mon Sep 17 00:00:00 2001 From: Taniko Yamamoto <99076687+YukisCoffee@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:43:32 +0900 Subject: [PATCH 1/3] UIRibbon Caption Icon Fix 1.0 --- mods/ribbon-caption-icon-fix.wh.cpp | 76 +++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 mods/ribbon-caption-icon-fix.wh.cpp diff --git a/mods/ribbon-caption-icon-fix.wh.cpp b/mods/ribbon-caption-icon-fix.wh.cpp new file mode 100644 index 000000000..44bdee5e9 --- /dev/null +++ b/mods/ribbon-caption-icon-fix.wh.cpp @@ -0,0 +1,76 @@ +// ==WindhawkMod== +// @id ribbon-caption-icon-fix +// @name UIRibbon Caption Icon Fix +// @description Fixes the position of the caption icon in UIRibbon. +// @version 1.0 +// @author Taniko Yamamoto +// @author:ja 山本たにこ +// @github https://github.com/YukisCoffee +// @include mspaint.exe +// @include explorer.exe +// @include wordpad.exe +// ==/WindhawkMod== + +#include + +int (*GetSystemMetrics_orig)(int); +int GetSystemMetrics_hook(int nIndex) +{ + switch (nIndex) + { + case SM_CXFRAME: + return 0; + } + + return GetSystemMetrics_orig(nIndex); +} + +int (*GetSystemMetricsForDpi_orig)(int, int); +int GetSystemMetricsForDpi_hook(int nIndex, int dpi) +{ + switch (nIndex) + { + case SM_CXFRAME: + return 0; + } + + return GetSystemMetricsForDpi_orig(nIndex, dpi); +} + +BOOL Wh_ModInit() +{ + Wh_Log(L"Init"); + + HMODULE user32 = GetModuleHandleW(L"user32.dll"); + + if (!user32) + { + Wh_Log(L"Failed to load user32 module!"); + return FALSE; + } + + if (!Wh_SetFunctionHook( + (void *)GetProcAddress(user32, "GetSystemMetrics"), + (void *)GetSystemMetrics_hook, + (void **)&GetSystemMetrics_orig + )) + { + Wh_Log(L"Failed to hook GetSystemMetrics"); + } + + if (!Wh_SetFunctionHook( + (void *)GetProcAddress(user32, "GetSystemMetricsForDpi"), + (void *)GetSystemMetricsForDpi_hook, + (void **)&GetSystemMetricsForDpi_orig + )) + { + Wh_Log(L"Failed to hook GetSystemMetricsForDpi"); + } + + return TRUE; +} + +void Wh_ModUninit() +{ + Wh_Log(L"Uninit"); +} From f88ca7ee00979d3769e75283b1dac496a3fd250e Mon Sep 17 00:00:00 2001 From: Taniko Yamamoto <99076687+YukisCoffee@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:21:20 +0900 Subject: [PATCH 2/3] Update ribbon-caption-icon-fix.wh.cpp --- mods/ribbon-caption-icon-fix.wh.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/mods/ribbon-caption-icon-fix.wh.cpp b/mods/ribbon-caption-icon-fix.wh.cpp index 44bdee5e9..91cca23ae 100644 --- a/mods/ribbon-caption-icon-fix.wh.cpp +++ b/mods/ribbon-caption-icon-fix.wh.cpp @@ -11,10 +11,22 @@ // @include wordpad.exe // ==/WindhawkMod== +// ==WindhawkModReadme== +/* +# UIRibbon Caption Icon Fix + +Fixes the position of the caption icon in UIRibbon, which is ordinarily broken since Windows 10, due to +window frames becoming only 1 pixel wide. Whenever ribbons are displayed on a custom theme with wider +borders, the icon will have extra indentation, which is not desirable. + +![Preview](https://raw.githubusercontent.com/YukisCoffee/images/main/uiribbon%20fix.png) +*/ +// ==/WindhawkModReadme== + #include -int (*GetSystemMetrics_orig)(int); -int GetSystemMetrics_hook(int nIndex) +int (WINAPI *GetSystemMetrics_orig)(int); +int WINAPI GetSystemMetrics_hook(int nIndex) { switch (nIndex) { @@ -25,8 +37,8 @@ int GetSystemMetrics_hook(int nIndex) return GetSystemMetrics_orig(nIndex); } -int (*GetSystemMetricsForDpi_orig)(int, int); -int GetSystemMetricsForDpi_hook(int nIndex, int dpi) +int (WINAPI *GetSystemMetricsForDpi_orig)(int, int); +int WINAPI GetSystemMetricsForDpi_hook(int nIndex, int dpi) { switch (nIndex) { From 597cc795b52ef659f3b038e9e914d35e776883dd Mon Sep 17 00:00:00 2001 From: Taniko Yamamoto <99076687+YukisCoffee@users.noreply.github.com> Date: Mon, 29 Jul 2024 06:44:50 +0900 Subject: [PATCH 3/3] ribbon-caption-icon-fix 1.0.1 Changed the license. --- mods/ribbon-caption-icon-fix.wh.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ribbon-caption-icon-fix.wh.cpp b/mods/ribbon-caption-icon-fix.wh.cpp index 91cca23ae..234745d14 100644 --- a/mods/ribbon-caption-icon-fix.wh.cpp +++ b/mods/ribbon-caption-icon-fix.wh.cpp @@ -2,7 +2,7 @@ // @id ribbon-caption-icon-fix // @name UIRibbon Caption Icon Fix // @description Fixes the position of the caption icon in UIRibbon. -// @version 1.0 +// @version 1.0.1 // @author Taniko Yamamoto // @author:ja 山本たにこ // @github https://github.com/YukisCoffee @@ -15,6 +15,9 @@ /* # UIRibbon Caption Icon Fix +*Copyright (C) 2024 Taniko Yamamoto. All rights reserved.* Please do not use in your projects without express +permission of the copyright holder. + Fixes the position of the caption icon in UIRibbon, which is ordinarily broken since Windows 10, due to window frames becoming only 1 pixel wide. Whenever ribbons are displayed on a custom theme with wider borders, the icon will have extra indentation, which is not desirable.