"Deleted the post about introducing a dark title bar without warning, and did not tell where the prob" (903067)

The original article is quite long, so I’ve attached the complete code that introduces a dark title bar for legacy Win32 apps with a simple improvement. This is to simplify the developer’s job.

But the administrator directly deleted the post and told that it was off topic. If you want to delete the post, please lock the post first and allow me to copy the content of the post to the local first.

You should then inform where feedback on this issue is required

Instead of directly deleting the post rudely.

I don’t think the developers need a guide. Basically, it’s as if a construction worker on a foreign construction site wants to explain to the workers there what they should do.

If they’ve introduced dark title bars for Unity (Windows), then I’d agree with you. If they haven’t done this, I can only assume they need a guide.

I’ve attached your post for reference purposes. In any case this hasn’t been done because that doesn’t affect the menu bar which remains white and defeats the whole purpose of it.

I appreciate you taking the time to write up a detailed post about it but unfortunately it doesn’t help.

https://discussions.unity.com/t/758535/49

There has been this discussion since 2019.

Regarding the menu bar, I hate to underestimate your skill level. If you are unwilling to migrate to Windows App SDK or use XAML island considering cross-platform compatibility, I assume that the menu bar control is based on WPF or WinForms, then you can get a black menu bar and menu with simple appearance customization.

https://stackoverflow.com/questions/24698755/how-to-change-the-background-of-the-menuitem-on-mouseover-in-wpf

What was deleted was a duplicate of a post you had already made in the relevant thread.

https://discussions.unity.com/t/758535/48

Unity is based on the old Win32 API. In any case migrating to a different UI framework would be a lot of work so this hasn’t been a priority.

Because it is based on Win32 API, I pointed out in the post that you don’t need to migrate to WindowsAppSDK or XAML island, you only need

  • This method is exactly for Win32 applications

  • This method is fully compatible with earlier versions of Windows (although you claim to have ended support for it. But even so, for Windows 8, or earlier versions of Windows, the API will not work without any compatibility issues, This change will be ignored.

  • This method also does not require complex customization of the window border, and only needs to add a few lines of code to run perfectly.

  • This approach also eliminates the need to migrate to the Windows App SDK or use a XAML island, which is currently the cheapest approach.

  • This is Microsoft’s official method for Win32 applications to adapt to dark title bars.

To enable the dark title bar, call a Desktop Windows Manager (DWM) function called DwmSetWindowAttribute on your top-level window, using the window attribute DWMWA_USE_IMMERSIVE_DARK_MODE. (DWM renders attributes for a window.)

The following examples assume you have a window with with a standard title bar, like the one created by this code.

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, 0,
     CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

First, you need to import the DWM API, like this.

#include <dwmapi.h>

After passing hWnd (the handle to the window you want to change) as your first parameter, you need to pass in DWMA_USE_IMMERSIVE_DARK_MODE as the dwAttribute parameter. This is a constant in the DWM API that lets the Windows frame be drawn in Dark mode colors when the Dark mode system setting is enabled. If you switch to Light mode, you will have to change DWMA_USE_IMMERSIVE_DARK_MODE from 20 to 0 for the title bar to be drawn in light mode colors.

The pvAttribute parameter points to a value of type BOOL (which is why you made the BOOL value earlier). You need pvAttribute to be TRUE to honor Dark mode for the window. If pvAttribute is FALSE, the window will use Light Mode.

#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif


BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   BOOL value = TRUE;
   ::smile:wmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

Lastly, cbAttribute needs to have the size of the attribute being set in pvAttribute. To do easily do this, we pass in sizeof(value).

Your code to draw a dark windows title bar should look like this.

More Document:
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes

The light main menu bothers me more than the light title bar.
Most other legacy UI programs that use their own color scheme completely reimplement the title bar.

The main menu could implement unity with their own UIT, like the rest of the UI. The reason why Unity use the native UI menu for this is probably that it works differently in different OSs. But I saw that Jetbrain recently switched its main menu, at least in the Mac version, to its own main menu within the window.

This post is poorly readable and in a very old archive, so I started a new thread

As I mentioned, that doesn’t make the menu dark:

8662551--1166457--upload_2022-12-14_13-45-15.png

You can try it out yourself with the attached script.

Also accessibility. The OS native menu bar provides a lot of functionality that’s not trivial to replicate.

8662551–1166460–DarkMode.cs (950 Bytes)

Amazing!

I know, I mean exactly the system’s native menu, I’m not sure which framework the menu uses, WPF? Or WinForms?

Probably neither, but directly Win32 C++ API, or C# binding as in the dark mode file excample.

I wrote before, raw Win32: https://learn.microsoft.com/en-us/windows/win32/menurc/menus

Ideally, their colors are specified by the user’s msstyle file

This makes it quite difficult to customize the color. Have you considered using a framework such as MFC or WinForms?

MFC doesn’t help, as far as I know (although I’m far from an expert at MFC), it doesn’t have any controls around menu color.

WinForms/WPF are not viable for us. Not only that’d require rewriting all UI logic, they are both only supported on .NET Framework/.NET Core and Unity uses Mono, which doesn’t support them. Also, having a low level UI framework in C# doesn’t really work because it would not survive domain reloads.

Ideally, Microsoft just added support for customizing menu color without having to rewrite how we create windows/pump messages. There’s a lot of complicated code there and it’d take multiple man work years to switch to something else.

https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/using-the-xaml-hosting-api

https://github.com/microsoft/Xaml-Islands-Samples/blob/master/Samples/Win32/ReadMe.md

will you consider that using XAML island to build the menu bar? only menu bar

We might consider it. Given that we dropped support for Windows 7 and earlier Windows 10 versions opens up the possibility of doing it. That said, it isn’t without downsides: XAML runtime is huge and using it just for the menu bar might be overkill.

That said, as far as I know, this isn’t on the roadmap. And I am not on the team working on this stuff. There have been talks internally about prioritizing it but so far it didn’t make the list.

I would say that in the end it’s easier in windows to omit the native menu and create the menu using the editor UI, that would also fit better with the rest of the editor. As I said, Jetbrain has at least done that with PHPStorm, let the other editors like Rider do the same, but I only have PHPStorm on the Mac, so I noticed that the menu bar had changed. I suspect Jetbrain already had both variants, custom menubar in Window and native menubar on Mac. Their editor on Window is completely the same color scheme, title bar and menu bar.

Yes they are huge。

Could you please ask your colleagues to come and reply to this thread?