Code Monkey home page Code Monkey logo

wincentertitle's Introduction

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.

Installation

  • Download archive from releases
  • Unpack to folder of your choice (preconfigured for C:\WinCenterTitle)
  • Edit WinCenterTitle.xml and edit line 40, which contains path to application, according to your system
  • Register scheduled task which will enable the tweak at startup: run install.bat as administrator. This is one way of running the application using the SYSTEM account, which is required in order to be able to hook into DWM.
  • VERY IMPORTANT: Hooking DWM requires special permissions for the folder that contains the application and the library. Make sure folder owner is set to Administrators and that the Users group is added as well, with default permissions (Read & execute, List folder contents, and Read). Otherwise, the application will terminate with error code -6, being unable to hook the library into Desktop Window Manager. Also, in that folder, make sure you have a folder called "symbols", with Full Control permissions for Users group.
  • Reboot system or manually run the created scheduled task. This will center title bars for all windows. You can close or rerun the application from Task Scheduler, allowing you to toggle between center aligned and left aligned (default) title bars. No DWM restart is required and the library should leave DWM in a clean state when unloading.

To do

  • Hook window activation and optionally hide icon in title bar (could be achieved with SetWindowThemeAttribute)
  • Add option to center between window margins, as opposed to space between icon and window controls
  • User settings, system tray icon, configuration GUI etc (unlikely)

How it works

The application injects into DWM and hooks DrawText method that is used to compute the area, and draw the title bar text for the window. By doing so, we achieve the effect with least amount of overhead, as the method is called by DWM only when the window is an unskinned (no custom client side decoration aka no DwmExtendFrameIntoClientArea). After injecting, the application monitors DWM and reinjects should it crash or reload by user action.

This means that all regular windows will have their title bar text centered. Custom skinned windows require more attention; in particular, heavy skinned ones are impossible to modify unless hacks specific to the application are employed - think Visual Studio, Visual Studio Code (fortunately, it is already centered), Office (already centered as well). However, a special class of windows are left left-aligned by this tool, but we can do more regarding them: ribbon windows - think File Explorer, Paint, WordPad etc. These respect a property (CONTENTALIGNMENT) specified in the theme style file (the default is aero.msstyles). To patch this, a rather complicated process is required:

  1. Enable custom themes on your system by patching uxtheme. For this, I used UltraUXThemePatcher, but the tool does not matter.
  2. Stop WinCenterTitle if running, and then kill dwm in order to get a fresh new process.
  3. Make a copy of aero folder and aero.theme from C:\Windows\Resources\Themes in the same folder. I called mine test.theme and folder test.
  4. Rename aero.msstyles to test.msstyles from aero folder, and aero.msstyles.mui to test.msstyles.mui from aero\en-US folder. These two steps may require you to take ownership of the files.
  5. Download msstyleEditor and open the test.msstyles file in it. In the left, browse for Window\CAPTION. On the right, click + near Common and choose CONTENTAALIGNMENT from the list. Set it to Right (there is currently a bug in msstyleEditor and Centered is labeled Right and vice versa; so, when you see Right, it means Center). Repeat this for Window\MAXCAPTION on the left (credits: https://www.sevenforums.com/customization/186924-center-titlebar-text.html). Make sure to save the newly edited file at C:\Windows\Resources\Themes\test\test.msstyle.
  6. Edit C:\Windows\Resources\Themes\test.theme, and make sure Path in VisualStyles section reads %ResourceDir%\Themes\test\test.msstyles. Also, change DisplayName in Theme section to whatever you like, I changed mine to @%SystemRoot%\System32\themeui.dll,-2014 which will name the theme Windows Basic.
  7. Apply the new theme from Personalization\Themes in Settings. Notice how the title bar text is centered in Explorer. There is one issue though: the title bars are now colored, instead of default white/black. This is because DWM contains a check for the name of the msstyles file. If it is called aero.msstyles, title bars will be painted white/black, depending on whether you are on light/dark theme in Settings. If the msstyles file has any other name (like in our case), the title bar will have whatever color the msstyles file specifies, or in the case of this renamed aero.msstyles, it will use your accent color no matter if you have 'Show accent color on the following surfaces: Title bars and window borders' in Personalization\Colors in Settings checked or not. To override this behavour, WinCenterTitle has a small code block that identifies the in memory flag of DWM that holds the status of whether the theme is called aero.msstyles and overrides its value to 1, meaning that the theme is called aero.msstyles, despite its actual name, and forcing DWM to render the title bars using the default behavior. So, to complete this guide, start WinCenterTitle now and observe how the title bars will have centered text for all windows, including ribbon applications (File Explorer, WordPad, Paint etc). After aprox. 10 seconds, the title bars will also revert to their default white/black apparance, if you had them this way previously.

License

Hooking is done using the excellent funchook library (GPL with linking exception), which in turn is powered by the diStorm3 (3-clause BSD) disassembler. Thus, I am offering this under the GNU General Public License Version 2.0, which I believe is compatible.

Compiling

The following prerequisites are necessary in order to compile this project:

  • Microsoft C/C++ Optimizing Compiler - this can be obtained by installing either of these packages:

    • Visual Studio - this is a fully featured IDE; you'll need to check "C/C++ application development role" when installing. If you do not require the full suite, use the package bellow.
    • Build Tools for Visual Studio - this just installs the compiler, which you'll be able to use from the command line, or from other applications like CMake

    Download either of those here. The guide assumes you have installed either Visual Studio 2019, either Build Tools for Visual Studio 2019.

  • CMake - for easier usage, make sure to have it added to PATH during installation

  • Git - you can use Git for Windows, or git command via the Windows Subsystem for Linux.

Steps:

  1. Clone git repo along with all submodules

    git clone --recursive https://github.com/valinet/WinCenterTitle
    

    If "git" is not found as a command, type its full path, or have its folder added to PATH, or open Git command window in the respective folder if using Git for Windows.

  2. Compile funchook

    cd libs
    cd funchook
    md build
    cd build
    cmake -G "Visual Studio 16 2019" -A x64 ..
    cmake --build . --config Release
    

    If "cmake" is not found as a command, type its full path, or have its folder added to PATH.

    Type "Win32" instead of "x64" above, if compiling for x86. The command above works for x64.

  3. Compile WinCenterTitle

    • Double click the WinCenterTitle.sln to open the solution in Visual Studio. Choose Release and your processor architecture in the toolbar. Press F6 to compile.

    • Open an "x86 Native Tools Command Prompt for VS 2019" (for x86), or "x64 Native Tools Command Prompt for VS 2019" (for x64) (search that in Start), go to folder containing solution file and type:

      • For x86:

        msbuild WinCenterTitle.sln /property:Configuration=Release /property:Platform=x86
        
      • For x64:

        msbuild WinCenterTitle.sln /property:Configuration=Release /property:Platform=x64
        

    The resulting exe and dll will be in "Release" folder (if you chose x86), or "x64\Release" (if you chose x64) in the folder containing the solution file.

That's it. later, if you want to recompile, make sure to update the repository and the submodules first:

git pull
git submodule update --init --recursive

wincentertitle's People

Contributors

valinet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wincentertitle's Issues

How to left the title bar in Windows 8 RTM build 9200.

I've try the method in another issue which title is released by Ygjsz. But during my tries, the way which can left the 8.1 title bar does not work in 9200. So can you study how to left the title bar in 9200? Thank you.

After install in Windows 21H1 desktop turns dark when maintaining mouse button pressed

Hello,

I installed WinCenterTitle in a clean W10 Home Edition version 21H1, build 19043.1348.
Unfortunately it seems no task was created in Task Scheduler and when I restarted my PC, the desktop was acting up.
If I kept the mouse button pressed the selection area by dragging the mouse would turn black. This problem begins any time I open a new app.
Eventually I have to restart Explorer because the entire desktop area freaks out.

How do I do to uninstall and revert the changes done? I deleted the WinCenterTitle folder but I still have the same issues.

Untested on x86 (IA-32), arm64

Since my system is amd64 (x64), I don't test the application on neither IA-32 (x86), nor arm64. If someone could report whether it works for them on x86, that'd be greatly appreciated. When I say x86, I mean running on a true 32-bit system, not under WOW64 (it probably won't run there, since dwm is still 64-bit when running as x86 under WOW64, and so addresses will probably turn up bad). Please report on an a build of the application against the latest commits and source, there are some updates which haven't made it to release yet (mention the commit you compiled against in the comments, please).

Thank you.

1.2.0.0 is incompatible with 1809

Attempting to run 1.2.0.0 in the 1809 version of Windows results in the title text not budging, however symbols are still downloaded. Folder permissions are correct. Trying to run this in a 20H2 VM works fine. 1.1.0.0 also works fine.
Kinda not surprised about this, so it's up to you if you want to add in compatibility. Would give more info if there was a log feature.

Overrides msstyle titlebar colors

When dwm is patched and scheduler is running, doesn't matter which msstyle you pick, it will always be white themed.
Here's one example:
image
Firefox and explorer windows have the correct titlebar color, meanwhile, taskmanager and other win32 apps have it set to white.

Expected behaviour:
Titlebar being dark when darkmode is enabled

edit: i have double checked the msstyle theme atlas and properties with WSB and couldn't find any relation between them and the mentioned issue.

edit²: Not sure if that information helps, but applying the theme with firefox window open makes it use dark variant, but not taskmanager and others.

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

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

Please continue work on Aero Glass and make it a separate project

Your work on the glass branch of this project specifically is amazing so far, and I can't wait to see it when it has been fully developed. However, your last commit to it has been in November 2020, and I am worried that you have given up working on it, which would be a shame, as it is the only way to get Aero Glass on Windows 10 2004+ discounting Stardock which is paywalled. Also, a few small bug reports: DWM opens as a console window, closing it just restarts DWM and the console window, and title text has an opaque white background on most windows. Asides from that, there are only minor issues which are due to it not being fully developed yet. You should also really consider making the glass branch into its own project, which would make it more visible when people search for « Aero Glass for Windows 10 » on search engines. I only found about this by searching for something which would give me centered title text (which it does excellently), and then seeing the issue where someone was asking for left-aligned text, which showed me the Aero Glass they had which led me to find out about the glass branch. Please make this is a separate project so more people know about this, please… and please continue work on it, it would be very much appreciated.

Cannot get handle to application on Windows 10 20H2

I run this application on my Windows 10 20H2, following https://github.com/valinet/WinCenterTitle#installation. But I get a Cannot get handle to application error message.

I run this exe in an administrated cmd. And the permissions of the WinCenterTitle and symbols folders are also set as Installation said. And the Command key in xml file is also modified.

Make sure folder owner is set to Administrators and that the Users group is added as well, with default permissions (Read & execute, List folder contents, and Read)

WinCenterTitle.exe /xml WinCenterTitle.xml
WinCenterTitle
==============
1. Hook Library Path: C:\Settings\WinCenterTitle\WinCenterTitleLibrary.dll
2. Hook Library Entry Point: 0x1dc0
3. LoadLibraryW address: -766050592
3. FreeLibrary address: -766064688
4. ERROR: Cannot get handle to application.

image

Title text on inactive title bar showing white background when using custom Win 10 themes

Hi. There's issue in title text on inactive title bar. The inactive title text showing white opaque background regardless using WinCenterTitle.exe or WinCenterTitle_nonAero.exe. I using Windows 10 Home version 20H2 OS Build 19042.572 and i using custom theme patched with Universal UXThemePatcher.

Annotation 2021-03-09 111928

I have attached the preview of this issue.

Thank you for your attention.

Report

Just a report about the question that I mentioned last time , you can close the issue immediately.
The gap was cauesd by AeroGlass from Big Muscle , when I disbale the AeroGlass , the gap disappeared.
So I used your code and set the value to -17
mov rax, -17
ret
And it looks prefectly.
Thanks a lot.
(Sorry for my bad English)
截屏2021-02-09 上午9 53 14

Title's text becomes blurry

Title's text becomes blurry after applying WinCenterTitle. You will notice it if the Title's text is long enough.

Before:

Before

After:

After

The center of the text is NOT blurry. The farther from the center, the text becomes more blurry.

Another problem about left align the text

Sorry for disturbing you again.
I found an another problem.
There's a little gap between the program icon and the text. And how to move the text closer to the program icon just like Windows 7 ?
untitled

Cannot get handle to application?

Hi there, I'm sorry to be "that guy" but I've followed all your directions carefully and still can't get the app to hook successfully. I installed it to C:\WinCenterTitle, and made the owner of the folder the "Administrators" account and gave full permissions to "Users". Nevertheless, executing the exe in an admin Command Prompt yields the following:
Version of Win10: 19042.1586

WinCenterTitle

  1. Hook Library Path: C:\WinCenterTitle\WinCenterTitleLibrary.dll
  2. Hook Library Entry Point: 0x1e20
  3. LoadLibraryW address: -1349779744
  4. FreeLibrary address: -1349793840
  5. ERROR: Cannot get handle to application.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.