Skip to content

Commit

Permalink
Updated offsets to work with the most recent versions of Windows
Browse files Browse the repository at this point in the history
(tested with Windows 11 22000.176, but it probably works on
everything in between last year and today, most probably also on
19041/2/3 with latest CUs - some member was added to the beginning
of the CText class and it shifted everything further down by 2...
  • Loading branch information
valinet committed Sep 3, 2021
1 parent b986ab5 commit 2959f9a
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions WinCenterTitleLibrary/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int64_t CTextValidateResourcesHook(
// label based on a check of whether the label size exceeded the window
// size; so, by setting the label size to a very large value, DWM is
// tricked into thinking the overflow is always happening
val = ((DWORD*)g_CTextInstance + 100);
val = ((DWORD*)g_CTextInstance + 102); // 100
if (*val < ENTIRE_TITLEBAR)
{
*val += ENTIRE_TITLEBAR;
Expand Down Expand Up @@ -132,19 +132,25 @@ int64_t CMatrixTransformProxyUpdateHook(

if (g_CTextInstance)
{
// this is the width of the title bar label containing the text
double v1 = *((DWORD*)g_CTextInstance + 100);
// offsets changed in some update to uDWM from 2021
// probably a new member was added to the CText class that
// moved everything further down; a SHORT most probably
//
// this is the width of the title bar label containing the text - get it from CText::ValidateResources, there is a rect
double v1 = *((DWORD*)g_CTextInstance + 102); // 100
// this is the size available for the label (the size between the
// window icon, or the left window margin, and the caption buttons, or the
// right window margin)
double v3 = *((DWORD*)g_CTextInstance + 30);
// this is the height of the titlebar text (UNUSED)
double v4 = *((DWORD*)g_CTextInstance + 31);
// this is the width of the window icon
double v6 = *((DWORD*)g_CTextInstance + 32);
// right window margin) - get it from CText::SetSize
double v3 = *((DWORD*)g_CTextInstance + 32); // 30
// this is the height of the titlebar text (UNUSED) - get it from CText::SetSize
double v4 = *((DWORD*)g_CTextInstance + 33); // 31
// this is the width of the window icon - from CText::UpdateLayout and CVisual::UpdateLayout
// there is something where it substracts 2 values from another, it looks
// like it tries to compute the width available for the text
double v6 = *((DWORD*)g_CTextInstance + 34); // 32
// this is the width of the window caption buttons (for example,
// Close, Minimize, Maximize etc)
double v5 = *((DWORD*)g_CTextInstance + 33);
// Close, Minimize, Maximize etc) - from CText::UpdateLayout and CVisual::UpdateLayout
double v5 = *((DWORD*)g_CTextInstance + 35);
// this also contains the width and height:
// tagSIZE st = *((tagSIZE*)g_CTextInstance + 15);
// where tagSIZE is a struct of 2 LONGs (width, and height)
Expand Down Expand Up @@ -499,6 +505,18 @@ __declspec(dllexport) DWORD WINAPI main(
);
}

/*
The address of titlebar_color is determined like this:
1. Note that when the theme name is "aero.msstyles", DWM sets a
flag that makes the title bar white despite the theme's color
2. To locate that flag, look in "CDesktopManager::LoadTheme",
where it uses the string "aero.msstyles", it sets some variable
into some member of the class.
3. A pointer to that class is also stored globally in a
variable called "g_pdmInstance"; this can be verified by
looking in "CDesktopManager::Create"
*/
HANDLE hudwm = GetModuleHandle(TEXT(MODULE_NAME_UDWM));
uintptr_t* g_pdmInstance = (uintptr_t*)(
(uintptr_t)hudwm +
Expand Down

3 comments on commit 2959f9a

@mzso
Copy link

@mzso mzso commented on 2959f9a Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi!
What does "differences are in how the title bars are colored" mentioned in the release notes mean in practice?

@valinet
Copy link
Owner Author

@valinet valinet commented on 2959f9a Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember, if you use a theme called other than “aero.msstyles”, the title bar will always get colored in the accent color, no matter what the setting to “Show color on Start, taskbar and title bar” in Settings is set to. So, this application also patches the variable that indicates to DWM whether to draw the title bar white, so that when you use a custom theme, you get the behavior from Aero. This is useful when you adjust the title bar text alignment in the theme file (CONTENTALIGNMENT) and get a different aero_modified.msstyles let’s say and when you use that you suddenly lose the white title bar and get your accent color on it. Yeah, you could replace aero.msstyles altogether, but to avoid replacing system files, I also added this feature. This isn’t useful though when you use a custom theme and the title bars suddenly become white despite expecting the theme to have them colored in some way. So there you don’t want this behavior…

Maybe the code needs a bit of refactoring and some better comments to explain what is going on, I admit, but fortunately the app is relatively stable, after all, all that change in newer DWM is just one more variable added to the struct that shifted everything down, the way it works internally otherwise is the same as a year ago.

@mzso
Copy link

@mzso mzso commented on 2959f9a Sep 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valinet
Thanks.

Please sign in to comment.