valinet / WinCenterTitle

WinCenterTitle is a simple tool that allows you to center align the text in Windows 10 titlebars, the same way it was in Windows 8, 8.1, or even 3.1.
GNU General Public License v2.0
153 stars 16 forks source link

Window title not centered in programs which place buttons on to the title bar #1

Closed second2050 closed 3 years ago

second2050 commented 4 years ago

Currently in windows of programs were buttons are placed on the title bar the window title is not centered. Is this intended or is this a bug?

Example 1 (Windows Live Photo Gallery 2012): image Left: Window from Photo Gallery without "In-Title-Bar-Buttons". Right: Window from Photo Gallery with "In-Title-Bar-Buttons".

Example 2 (Windows Live Writer 2012): image

valinet commented 4 years ago

Hi

Timing is excellent, it is just yesterday that I looked into this issue. The problem concerns applications that use a ribbon, like File Explorer, Paint, WordPad, as well as your examples. Specifically, these applications draw themselves the title, instead of DWM, based on the CONTENTALIGNMENT setting in the msstyles theme file that the system is using.

I have added relevant info in the README on how to patch the default aero.msstyles or any other style in order to center align that text, it is easier that way and it'd be way harder and prone to errors to do it by injecting via the daemon. Also, I have uploaded a pre-release binary that helps when using a custom theme (it forces DWM to choose the aero.msstyles code path, it is explained more thoughtfully in the README).

Here is an example of a ribbon window on my system with patched aero.msstyles:

image

Link to pre-release 1.1.0.0: https://github.com/valinet/WinCenterTitle/releases/tag/1.1.0.0

Also, please note that the new binary works, probably, only on Windows 10 Version 2004. The patched aero.msstyles should work with the old release as well (1.0.0.0), use that if 1.1.0.0 crashes.

second2050 commented 4 years ago

Thanks for the fast reply but there is a problem regarding 1.1.0.0 on my side: • Pre-Release 1.1.0.0 seems to crash my dwm: When loading 1.1.0.0 my screen goes black for a second and the window titles are not centered even when updating the window. When loading 1.0.0.0 my screen does not go black and window titles are centered when updating the window by clicking it.

Regarding the msstyle edit: That worked beautifully but shouldn't that also require a uxtheme patch? If yes, then you should add that to the readme.

valinet commented 4 years ago

That worked beautifully but shouldn't that also require a uxtheme patch? If yes, then you should add that to the readme.

Yes, naturally, I use UltraUXThemePatcher, but any patcher should work, I forgot about that. Theoretically, one could inject all offending applications and hook the Win32 function that is responsible for reporting the CONTENTALIGNMENT property (I don't think it is GetSystemMetrics, although I am not very familiar) and alter it accordingly, although, yeah, that will take a lot more time to implement and it is pretty cumbersome to inject all applications or maintain a whitelist. This solution is the quickest and works 100%, yet indeed, it requires theme signing to be off.

Pre-Release 1.1.0.0 seems to crash my dwm:

That's expected, I guess. The new binary edits a value in DWM so that when you use a custom msstyles, title bars are drawn white when you have the 'Show accent color on the following surfaces: Title bars and window borders' option in Personalization\Colors in Settings disabled. The location of that flag is hardcoded in the binary to the version of uDWM.dll on my system, and, as I said, I am using Windows 10 Version 2004 at the moment. In the future, I should get the address of the variable from the symbol file, dynamically, at run time, but again, that's a lot of work and not so much in return, when it takes 5 minutes to open uDWM.dll in IDA, ghidra or something similar and look for the offsets:

That's the principle of finding those values, doing that in code will take way more time than looking manually on the file. What probably differs in your case is the location of g_pdmInstance in memory of your uDWm.dll.

I should probably add this explanation to the README as well.

valinet commented 3 years ago

I have implemented logic that automatically downloads PDB files for dwm (uDWM.exe) and retrieves the addresses of necessary symbols to patch for “aero.msstyles” code path. This way, you will keep white title bars if using a custom theme, instead of colored ones, as is default. So, besides using the latest version, to get centered title bars in ribbon applications as well, one is required to disable theme signing using a uxtheme patcher, create a modified aero.msstyles with centered CONTENTALIGNMENT for window caption and maxcaption, and apply that. That’s the procedure for now. I consider this issue to be dealt with, I have added the necessary mentions to the README file as well.

You can binaries for the latest version (1.1.0.0) from Releases.

Thanks for the information.