Search code examples
windowsshellcontextmenutitlebar

Custom Title Bar Context Menu Actions


I want to add custom actions to every window's title bar context menu. The goal is to add an option like in the task view where you can move a window to a different virtual desktop. I was able to do this with hotkeys using GlobalHotKey and WindowsDesktop packages in C#. But I want to do it in the UI as well similar to some Linux desktop environments.

I know you cannot normally do this with the registry like you can with other context menus. When creating your own application I know you can use GetSystemMenu, AppendMenu, etc. and override WndProc to handle it. But this obviously will not work for what I am intending.

The application Moo0 Window Menu Plus achieves the desired effect but I have no idea how they do it.

I have a feeling the solution is probably somewhat hacky but I would still like to know how it could be done. I am open to using any language to achieve this.


Solution

  • You need to inject into the process, that is the only way to add a menu item.

    A shell hook will notify you with HSHELL_WINDOWCREATED when a appropriate window has been created. You can then inject into the process (with another hook type or CreateRemoteThread). Once you have your .DLL in the process you can subclass the window and change the system menu.

    You need to create both a 32-bit and 64-bit injection .DLL and I would recommend that you write it in native code, not C#.