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
155 stars 16 forks source link

How to left align the text in Winodws 8.1 titlebars? #7

Closed ygjsz closed 3 years ago

ygjsz commented 3 years ago

The tool can center align the text of Windows 10 titlebars , so how to left align the text in Winodws 8/8.1 titlebars ?

valinet commented 3 years ago

Similarly, I mean, one has to inspect DWM a bit and find the relevant sections of code (which should be similar, but will not be identical to Windows 10's dwm) and simply move the label to the left of the window. There is an internal struct that you can check to find info about the window (width, position of icon, position of window caption buttons etc).

ygjsz commented 3 years ago

When I try to run your tool on Windows 8.1 , this error appeared image And I don't know what caused this error. Maybe Windows 8.1's DWM is different from Windows 10's?

valinet commented 3 years ago

Debug builds are probably broken due to various reasons. Compile and run the application as a Release build.

Windows 10 DWM is DEFINITELY different than the Windows 8 or Windows 8.1 one.

ygjsz commented 3 years ago

I tried , it just doesn't throw out the error. But the tool still doesn't work.

valinet commented 3 years ago

So, it works. I mean, the error is gone. That it does not do anything visually, that’s some other thing. In its current form, this tool centers the text and only on Windows 10. It probably doesn’t work on Windows 7 either. DWM’s internal architecture changed quite a bit in 10 compared to 7/8. What is required, is for someone to take a look at udwm.dll from Windows 8.1 in IDA or Ghidra and find the relevant place where it draws the text and modify some integers there so that it gets left aligned.

I remember I looked at some point on the uDWM from 8.1 and it is even simpler: there is a function called GetLeftOffset or something like that that gives out something like window_width / 2 - text_width / 2 and that's how the text gets centered; one could patch that so that it returns 0 instead. Idk, I will install 8.1 in a VM and see what I can do, I will post here a binary should I have one for you to test, just wait a bit please, I am on my laptop and it will probably take a while (thanks Intel for shipping the same crappy low power CPU for 10 years)...

valinet commented 3 years ago

By the way, Windows 8.1 or Windows 8? I downloaded Windows 8.1, build 6.3.9600.

ygjsz commented 3 years ago

8.1

valinet commented 3 years ago

All right, try this precompiled version. All it does differently is to hook CText::GetLeftOffset from uDWM.dll and return 0. This is pretty much all that is required, all the other stuff is unnecessary on Windows 8.1. I think it may work on Windows 8 as well, but I haven't tested.

winlefttitle_w81.zip

valinet commented 3 years ago

Anyway, since the patch is so tiny on Windows 8.1, and also the fact that it does not get any more major updates, so system DLLs like the ones DWM uses are unlikely to change, a better solution would be do directly binary patch uDWM.dll and call it a day, just drop that patched version in system32 and you won't have to run any background daemon, which should be even more reliable. I will update this here and tell you how to do it, I am testing this now. I prefer this since I won't have to maintain a different variant of WinCenterTitle for Windows 8/8.1.

ygjsz commented 3 years ago

20210207223644 Works perfectly

valinet commented 3 years ago

20210207223644 Works perfectly

I am glad, sounds very good! But read this as well, maybe you find this solution better: here's the "tutorial" for binary patching uDWM.dll on 8.1 so that title bar text gets left aligned:

  1. Download HxD or any hex editor, make a copy of uDWM.dll from C:\Windows\System32 to Documents/Desktop/whatever and open the copy in HxD.
  2. Press Ctrl + F, click "Hex values", and type "909090909090FFF34883EC20488B4118448B897801000041BA020000008B".
  3. Click "Search all". In the window at the bottom of the screen, a single entry should be returned. Double click on it and some numbers will be highlighted in the editor.
  4. Position yourself after the last "90" in that sequence. Start typing "48c7c000000000c3". This should replace "FFF34883EC 20488B".
  5. Click "Save". You will get a new uDWM.dll.
  6. Replace the original file in system32. Go there in Explorer, take ownership of the original file, rename it to something like "uDWM_original.dll" and paste the newly patched uDWM.dll there.
  7. If Windows says the file is in use and you cannot perform the rename, it is because the file is in use by DWM, so you need to kill it but prevent winlogon.exe from respawning it; for this, download Process Explorer, run it as administrator, find winlogon in the list, right click and choose Suspend. Then, kill dwm.exe from Task Manager. The desktop will look weird but you can perform the rename and paste the new file in there. After that, go back to Process Explorer and click "Resume" on winlogon.exe and a new DWM will be spawned and the title text will be left aligned.

That's it. This way, you don't have to run anything else in the background. I recommend this solution, if you want to take the time, I just tested this as well, it works. Also, it applies to 8.1 (6.3.9600) only, for 8's DWM, it should be similar but maybe you have to look for something slightly different in HxD; the patched WinCenterTitle should work nevertheless, as that uses symbol names instead of hardcoded addresses/patterns which should be the same across 8 and 8.1.

I'd share the patched DLL here but I think there may be non-sensical copyright issues with MSFT etc. Applying the tutorial is not that hard anyway.

ygjsz commented 3 years ago

![Uploading 20210207231342.png…]() After patching the uDWM.dll Works perfectly too. Thanks a lot.

valinet commented 3 years ago

That's great to hear! You're welcome, I should have posted some info about this back then when I was actively developing this tool (last summer, I compared 8.1's DWM to 10's DWM, that's how I knew where to look now, I am amazed that I actually remembered the stuff; I wish I had the time and energy to finish the work on the "glass" branch of development as well) or at least help you out earlier, but I am very busy these days during the week; it's only on Sundays that I have some spare time so I can look into various stuff.

Anyway, I am glad I could help, at last.

kristibektashi commented 2 years ago

Is it possible to left-allign the text in Windows 8.1 even then DWM is not running (aka when using the Windows Basic theme)? Because binary patching uDWM.dll works perfectly when DWM is running but not when it's not running

valinet commented 2 years ago

If you binary patch a DWM related file, ofc it doesn’t affect when DWM is not running. To left align the title when the DWM is not running, I think you might succeed by editing the theme files.

kristibektashi commented 2 years ago

To left align the title when the DWM is not running, I think you might succeed by editing the theme files.

And how exactly can I edit the theme files?

valinet commented 2 years ago

Msstylesbuilder or sth like that. I don’t remember how exactly. Google is a good friend in this case.

Brds7t7 commented 2 years ago

I used HxD to search for the Hex Value "909090909090FFF34883EC20488B4118448B897801000041BA020000008B" in Win 8.1 Pro uDWM.dll, but all I get is this:

Capture-03

Win 8.1 is fully up-to-date with all Security Updates installed. Anyone know a way to find the correct value for my install?

teknixstuff commented 9 months ago

20210207223644 Works perfectly

I am glad, sounds very good! But read this as well, maybe you find this solution better: here's the "tutorial" for binary patching uDWM.dll on 8.1 so that title bar text gets left aligned:

  1. Download HxD or any hex editor, make a copy of uDWM.dll from C:\Windows\System32 to Documents/Desktop/whatever and open the copy in HxD.
  2. Press Ctrl + F, click "Hex values", and type "909090909090FFF34883EC20488B4118448B897801000041BA020000008B".
  3. Click "Search all". In the window at the bottom of the screen, a single entry should be returned. Double click on it and some numbers will be highlighted in the editor.
  4. Position yourself after the last "90" in that sequence. Start typing "48c7c000000000c3". This should replace "FFF34883EC 20488B".
  5. Click "Save". You will get a new uDWM.dll.
  6. Replace the original file in system32. Go there in Explorer, take ownership of the original file, rename it to something like "uDWM_original.dll" and paste the newly patched uDWM.dll there.
  7. If Windows says the file is in use and you cannot perform the rename, it is because the file is in use by DWM, so you need to kill it but prevent winlogon.exe from respawning it; for this, download Process Explorer, run it as administrator, find winlogon in the list, right click and choose Suspend. Then, kill dwm.exe from Task Manager. The desktop will look weird but you can perform the rename and paste the new file in there. After that, go back to Process Explorer and click "Resume" on winlogon.exe and a new DWM will be spawned and the title text will be left aligned.

That's it. This way, you don't have to run anything else in the background. I recommend this solution, if you want to take the time, I just tested this as well, it works. Also, it applies to 8.1 (6.3.9600) only, for 8's DWM, it should be similar but maybe you have to look for something slightly different in HxD; the patched WinCenterTitle should work nevertheless, as that uses symbol names instead of hardcoded addresses/patterns which should be the same across 8 and 8.1.

I'd share the patched DLL here but I think there may be non-sensical copyright issues with MSFT etc. Applying the tutorial is not that hard anyway.

Could you figure out what patch is required for Windows 8.0 (build 9200)?