Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question dark mode menu bar

Discussion in '2019.3 Beta' started by Remingthon, Sep 17, 2019.

  1. Remingthon

    Remingthon

    Joined:
    Feb 8, 2013
    Posts:
    8
    Hi, after presentation of new UI i look at site screenshot and see differences between promo and reality

    upload_2019-9-17_16-11-6.png

    here we see dark menu bar with white text .

    BUT in reality we see this

    upload_2019-9-17_16-12-31.png

    white menus and black text.

    So what does it mean? Is that fake promo or just not finished UI theme?
     
  2. Remingthon

    Remingthon

    Joined:
    Feb 8, 2013
    Posts:
    8
    I already change all os style ti dark, that not the option.
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    You can change the window border through the os however the menu is something we are still working on and has not made it into the current release. So to answer your question, it's not finished.
     
  4. Remingthon

    Remingthon

    Joined:
    Feb 8, 2013
    Posts:
    8
    Thanks, i will be waiting updates or switch to mac, there is no white bars on top ;)
     
    karl_jones likes this.
  5. CoMANDOR

    CoMANDOR

    Joined:
    Sep 21, 2015
    Posts:
    8
    And how can I turn on a dark theme?
     
  6. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    I have a dark menu bar with some finicky modifications to windows 10 system files to allow for a truly global dark theme / msstyle. but it's quite a pain to set up, I wouldn't really recommend it. I'm looking forward to Unity overriding it themselves and/or an option to hide the menu bar.. It's a cleaner look and many experienced devs and power users use alt key shortcuts to invoke and navigate the menu bar without reaching for their mouse, anyway so you might as well hide it when not in use.
     
    PeterTheEarthling likes this.
  7. PeterTheEarthling

    PeterTheEarthling

    Joined:
    Aug 6, 2015
    Posts:
    2
    Woah! I have been trying to do just that for a while, but I was only able to cahnge the top menu bar, do you think you could explain how you did that??
     
    Last edited: Apr 29, 2020
  8. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    @PeterTheEarthling I really don't want to post that info here for a few reasons:

    1. It's hacky and you can easily corrupt your system and need to repair or re-install Windows. e.g. you have to not just edit the registry but edit the permissions on the registry itself, properly defer automatic updates, which is no simple task on Windows 10.
    2. It may indirectly give the team at Unity (that is slated to implement this) a reason to deprioritize this task until however many months or years from now because there's some wacky hacky workaround detailed on the forums.

    Feel free to look up system level Windows 10 theme / skin hacks on your own though, they're out there.
     
    Last edited: May 5, 2020
  9. PeterTheEarthling

    PeterTheEarthling

    Joined:
    Aug 6, 2015
    Posts:
    2
    Ok, thank you. I did do a lot of research, but yeah it's pretty hacky and can easily corrupt things. Instead I wrote a windows api program using the magnifier api to look for the Unity window and invert the colors of the title bar.
     
  10. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    Funny that you say that, now in 2020 Mac has grey bars.
    It does not follow the OS style color but uses light grey or dark depending on the theme in unity.

    I can see the reasoning why but at the same time I would like to be able to choose between what unity chooses and what the Os chooses.

    Make this optional please
     
    PeterTheEarthling likes this.
  11. pavlopiy

    pavlopiy

    Joined:
    Dec 30, 2016
    Posts:
    1
    I am very grateful to Unity for making Dark Mode free for all users, thanks a lot! But this white menu bar on Windows is really really annoying (the problem does not exists on macOS though).
     
  12. ScreenwaveMedia

    ScreenwaveMedia

    Joined:
    Jul 8, 2020
    Posts:
    15
    Good to see this still being talked about. It bothers my OCD very much!

    It's partially Microsoft's fault, that some program types just don't respect Windows 10's dark mode (totally unfinished). It was bothering me so much that I switched Windows back to light mode (with accent color set to show on title bars), so at least it's consistent.

    I believe it's that certain app types don't use dark mode in their title by default. I'm not sure if Unity can just set a flag in their software or if it's more complicated than that, but I see they're gradually working on switching to their own menu bar (Visual Studio style) instead of using Windows' one. That would be nice to see.
     
    kfireven, hmeliq and LooperVFX like this.
  13. bricefr

    bricefr

    Joined:
    May 3, 2015
    Posts:
    61
    I'm glad to see I'm not the only one bothered by this ^^

    Coming from macOS and Linux where eveything is homogeneous and clean, it's really hard to accept from a big actor like Microsoft! I guess the menu bar not being themed as well is due to the win32 inheritance. UWP Windows 10 menu are following the system theme. So two options: hack Windows to force black bar menu (like landoth said) or wait for developers to start using another implementation of the menu (like Unity is actually doing it I guess).
     
    hmeliq, SamFZGames and LooperVFX like this.
  14. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Yeah, I'm also a MacOS user, but I need to use Windows on a laptop for my console ports and may or may not have to switch to a PC build after the ARM transition, depending on how good Rosetta 2 is. My one frustration is this inconsistency with Windows, it's just not nice to go from a nice looking system like MacOS to having to deal with these bright white bars on things you have explicitly asked Windows not to show by selecting dark mode. I mean I don't blame Unity, it's Microsoft's job to tell non-UWP programs to darken as well, which they haven't done (including their own programs like Skype etc.) but maybe they'll do it in a future update. But it's weird how the screenshots on the Unity website and things all seem to show a dark top bar.

    But for me even in light mode it's a problem, aesthetically/superficially anyway - It's clear that MS's goal in Win10 is to have the Windows UI itself sort of disappear/blend into the applications, where they used to have big borders around all Windows, they seem to be aiming for most apps to now blend with the UI with the title bar and minimize/maximize/close buttons as a seamless part of the program itself, kinda like Steam/Photoshop/Spotify had been doing for a long while, and they've attempted to retroactively apply it to older programs by having the top bar and menu appear white like most content is, and in some cases it does appear somewhat seamless but then when you get dark UI programs like Unity, it becomes really unsightly and broken looking unless that program uses its own UI. The fact that dark mode doesn't even override this on Win32 programs is crazy IMO.

    I think it can look a bit better by setting Windows to apply the accent colour to title bars and borders, but for some reason that only applies to the window you currently have in focus and you still end up with big white blocks everywhere else.

    Ultimately I'd love to see Unity use its own top UI to match the editor colours like the MacOS version does but I hope there's some way of making it support Windows 10 dark mode in the meantime if that takes a long time to do.
     
  15. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    in 2020 the OSX menu bar in unity 2020.2 is now too dark, I liked the OS default dark gray much better than the black. I mentioned it before.

    Black has too much contrast ans is therefore asking for attention from the eyes.
    Hope this will be tweaked a bit.
     
  16. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Nah I think it looks great. Just like Visual Studio Code, Discord, Spotify and others, using their own UI colours for the title bar without the divider there, I think that's a much better look.
     
    kfireven likes this.
  17. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    It's fine that you like it, I just wish we could set the color, so everyone can choose what they like
     
  18. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
    This is 2020, one black area

    Screenshot 2020-09-15 at 00.50.59.png

    This is 2019, It looks cleaner to me because its clear what is the os menu bar, what is the unity title bar and what is the unity toolbar

    Screenshot 2020-09-15 at 00.49.47.png
     
  19. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    I see it. I much prefer the seamless 2020 one without the random grey bar at the top.

    Anyway we're getting off topic, I want the Unity devs to see our requests for the Windows version fix :)
     
    LooperVFX likes this.
  20. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    We did look Into it however there isn't actually any documented Windows API that lets you change the color of the bar. That means we would have to draw our own bar which makes things more complicated than a simple color change. So it's something we want to do but it's not as simple as it sounds. We are still looking into it though so no definite answer yet.
     
    LooperVFX likes this.
  21. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
  22. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    hmeliq and LooperVFX like this.
  23. SamFZGames

    SamFZGames

    Joined:
    Mar 2, 2014
    Posts:
    52
    Understood! It makes a lot of sense, and as I suspected it’s Windows’s fault. Microsoft made a Dark Mode feature which doesn’t actually tell most apps to go into dark mode, heh.

    Would love to see a seamless bespoke UI for Unity but I totally understand this stuff takes time.
     
    TaroBall, karl_jones and LooperVFX like this.
  24. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
  25. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    @Aurigan I know your intention is to be helpful but can you please edit your post to not link directly to these Windows UI / Theme hacks? Let people seek these out on their own and risk causing damage / corruption to their operating system. Even if they do get it working, it only lessens popular demand in the community for a fix and prolongs Unity actually addressing this issue properly.
     
    TaroBall and Marc-Saubion like this.
  26. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    @karl_jones Thank you for your responses here on this topic. Here is another repo under MIT license that may prove useful: "Example (win32) application shows how to use undocumented dark mode API introduced in Windows 10 1809." It has been maintained / tested on the most recent version of Windows 10 released just a few months ago as well.
    https://github.com/ysc3839/win32-darkmode

    I found it linked from this stackoverflow topic: "Win10 dark theme - how to use in WINAPI?" which explains in further detail that Microsoft created an internal API for this for "Desktop" / win32 / WINAPI applications of their own, such as File Explorer. I would imagine if any large developer could get Microsoft's blessing to use this currently undocumented API, it would be one such as Unity.
    https://stackoverflow.com/questions/53501268/win10-dark-theme-how-to-use-in-winapi
     
    karl_jones likes this.
  27. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    The solution suggested by @Aurigan is actually incredibly helpful, thank you, the white bar was bothering me for ages and now it's gone. I highly doubt that Unity team's issues prioritisation will be affected by wheather a workaround is known or not. It's apparent from their presentation that they already know and use this themselves.
     
  28. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    https://en.wikipedia.org/wiki/Eating_your_own_dog_food
     
  29. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
  30. tarsss

    tarsss

    Joined:
    Oct 19, 2018
    Posts:
    9
    Any updates on this?
    I just can't understand what tooks them so long to imlement such (on the first glance) easy features. Look at the Windows explorer in the dark theme, its window top is plain black. Why can't Unity do this as well?
    upload_2021-3-21_15-54-7.png
     
  31. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
    Because Microsoft uses an internal API to theme these elements in their own Desktop / win32 / WINAPI apps, like explorer, and API that they don't (yet) officially support 3rd party developers in using. Read my previous posts for more information. There's nothing stopping Unity from engaging Microsoft in talks to "officially" use this API, they have the leverage to do so, though negotiations like that can take time if they go anymore at all. It would be far less technical work than rewriting all of the menus in Unity to draw a completely custom UI. It is also known the next major release of Windows 10 version 21H2 codename "Sun Valley" will have an overhauled UI with better dark theme support in general, so there is hope for these APIs to improve / become public at that point.
     
    Ksanone, TaroBall and tarsss like this.
  32. ZealUnity

    ZealUnity

    Joined:
    Apr 13, 2014
    Posts:
    64
    Has this been fixed? Still seems like the menu/title bar is white...
     
  33. WBonX

    WBonX

    Joined:
    Aug 7, 2018
    Posts:
    62
    It is actually quite important since it could easily introduce burnin in modern OLEDs
     
  34. tarsss

    tarsss

    Joined:
    Oct 19, 2018
    Posts:
    9
    I can't even find such issue on Unity's Issue Tracker. Honestly, it is little thinks like that that always make me want to quit this engine and never deal with all its compomises.
     
  35. LooperVFX

    LooperVFX

    Joined:
    Dec 3, 2018
    Posts:
    180
  36. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    437
    any news?
     
  37. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Sorry, no good news at the moment. We are still using an older version of the windows API so we cant take advantage of these new features at the moment. We don't plan on switching to the newer API any time soon, mainly because such changes introduce other unintended consequences.

    We hope to have some sort of solution when we refactor our windowing system, but that can be a long way off at the moment.
     
    LooperVFX likes this.
  38. lukas_sf

    lukas_sf

    Joined:
    Apr 17, 2022
    Posts:
    2
    Someday :)
    unityMenuBar.jpg
     
    Thimo_, kfireven and LooperVFX like this.
  39. kfireven

    kfireven

    Joined:
    Oct 18, 2016
    Posts:
    38
    It's Microsoft's mess, when the OS dark mode is on, then they should change all these win32 app title bars, menu bars, dialog boxes, borders... to black. But they are keeping them white like it's 1995.
     
    LooperVFX likes this.
  40. lukas_sf

    lukas_sf

    Joined:
    Apr 17, 2022
    Posts:
    2
    To be fair, it doesnt really need to be synced with OS Settings (still would be nice) to make it dark (or any other color). You can just build your "own" title bar there (like e.g. Adobe does it since like 2008). I understand that this has maybe not the highest priority but its also a bit funny that the "Game Engine" is literally the last software I use that still has this ugly white title bar. Would be also nice to remove this unnecessary new line for the menu itself (as suggested in last post). It just make the whole engine looks more polished (even your own marketing team only uses the dark menu versions ;)).
     
    Last edited: Apr 25, 2022
    mikodibiitsi likes this.
  41. M_oenen

    M_oenen

    Joined:
    Oct 21, 2015
    Posts:
    5
    I'm using a package called "Fullscreen Editor". I changed the code to show the task bar at bottom. Press F6 will show or hide the menu bar.
    IMG_2406.JPG Snipaste_2022-05-20_21-25-02.png
     

    Attached Files:

  42. kfireven

    kfireven

    Joined:
    Oct 18, 2016
    Posts:
    38
    FYI, Paint.NET just updated their (ancient) win32 app to make the title bar and menu bar black in dark mode, and it looks beautiful, if such a tiny team can do it, no reason why massive Unity can't.
    upload_2022-5-29_21-25-3.png
     
    pmenefee, Thimo_ and LooperVFX like this.
  43. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Can you not use windows api at all for these button/title, render custom ones and use whatever theme is set in Unity?
     
  44. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,527
  45. Haunt3rr

    Haunt3rr

    Joined:
    May 19, 2020
    Posts:
    1
    I'd be super grateful if y'all do cuz I'm planning to move over to an OLED display, and this could cause a burn in concern
     
  46. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    "You can change the window border through the os"
     
  47. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes

    了解何时启用深色模式
    第一步是跟踪颜色模式设置本身。这将使您可以调整应用程序的绘画和渲染代码以使用深色模式颜色集。这样做需要应用程序在启动时读取颜色设置,并知道在应用程序会话期间颜色设置何时更改。

    要在 Win32 应用程序中执行此操作,请使用Windows::UI::Color并检测颜色是否可以分类为lightdark。要使用 Windows::UI::Color,您需要从 winrt 导入(在 pch.h 中)Windows.UI.ViewManagement 标头。

    C++

    " style="box-sizing: inherit; 轮廓颜色:继承;字体系列:SFMono-Regular、Consolas、“Liberation Mono”、Menlo、Courier、monospace;字体大小:1em;方向:ltr;边框:0px;填充:0px;行高:1.3571;显示:块;位置:相对;">#include <winrt/Windows.UI.ViewManagement.h>
    还在 main.cpp 中包含该命名空间。

    C++
    使用命名空间 Windows::UI::ViewManagement;
    在 main.cpp 中,使用此函数来检测颜色是否可以归类为light

    C++
    (8 * 128));
    }
    " style="box-sizing: inherit; 轮廓颜色:继承;字体系列:SFMono-Regular、Consolas、“Liberation Mono”、Menlo、Courier、monospace;字体大小:1em;方向:ltr;边框:0px;填充:0px;行高:1.3571;显示:块;position: relative;">inline bool IsColorLight(Windows::UI::Color& clr)
    {
    返回 (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
    }
    此函数执行对颜色感知亮度的快速计算,并考虑 RGB 颜色值中的不同通道对人眼看起来的亮度的贡献方式。它使用全整数数学来提高典型 CPU 的速度。

    笔记

    This is not a model for real analysis of color brightness. It is good for quick calculations that require you to determine if a color can be classified as light or dark. Theme colors can often be light but not pure white, or dark but not pure black.

    Now that you have a function to check whether a color is light, you can use that function to detect if Dark mode is enabled.

    Dark mode is defined as a dark background with a contrasting light foreground. Since IsColorLight checks if a color is considered light, you can use that function to see if the foreground is light. If the foreground is light, then Dark mode is enabled.

    To do this, you need to get the UI color type of the foreground from the system settings. Use this code in main.cpp.

    C++
    auto settings = UISettings();

    auto foreground = settings.GetColorValue(UIColorType::Foreground);
    UISettings gets all the settings of the UI including color. Call UISettings.GetColorValue(UIColorType::Foreground) to get the foreground color value from the UI settings.

    Now you can run a check to see if the foreground is considered light (in main.cpp).

    C++
    (IsColorLight(foreground));

    wprintf(L"\nisDarkMode: %u\n", isDarkMode);
    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">bool isDarkMode = static_cast<bool>(IsColorLight(foreground));

    wprintf(L"\nisDarkMode: %u\n", isDarkMode);
    • If the foreground is light, then isDarkMode will evaluate to 1 (true) meaning Dark mode is enabled.
    • If the foreground is dark, then isDarkMode will evaluate to 0 (false) meaning Dark mode is not enabled.
    To automatically track when the Dark mode setting changes during an app session, you can wrap your checks like this.

    C++
    (IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast<bool>(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    Your full code should look like this.

    C++
    (8 * 128));
    }

    int main()
    {
    init_apartment();

    auto settings = UISettings();
    auto foreground = settings.GetColorValue(UIColorType::Foreground);

    bool isDarkMode = static_cast(IsColorLight(foreground));
    wprintf(L"\nisDarkMode: %u\n", isDarkMode);

    auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    static bool s_go = true;
    while (s_go)
    {
    Sleep(50);
    }
    }
    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">inline bool IsColorLight(Windows::UI::Color& clr)
    {
    return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
    }

    int main()
    {
    init_apartment();

    auto settings = UISettings();
    auto foreground = settings.GetColorValue(UIColorType::Foreground);

    bool isDarkMode = static_cast<bool>(IsColorLight(foreground));
    wprintf(L"\nisDarkMode: %u\n", isDarkMode);

    auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast<bool>(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    static bool s_go = true;
    while (s_go)
    {
    Sleep(50);
    }
    }
    When this code is run:

    If Dark mode is enabled, isDarkMode will evaluate to 1.



    Changing the setting from Dark mode to Light mode will make isDarkModeRevoker evaluate to 0.



    Enable a Dark mode title bar for Win32 applications
    Windows doesn't know if an application can support Dark mode, so it assumes that it can't for backwards compatibility reasons. Some Windows development frameworks, such as Windows App SDK, support Dark mode natively and change certain UI elements without any additional code. Win32 apps often don't support Dark mode, so Windows gives Win32 apps a light title bar by default.

    However, for any app that uses the standard Windows title bar, you can enable the dark version of the title bar when the system is in Dark mode. 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.

    C++
    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.

    C++

    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">#include <dwmapi.h>
    Then, define the DWMWA_USE_IMMERSIVE_DARK_MODE macros above your InitInstance function.

    C++
    #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
    #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
    #endif

    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {

    Finally, you can use the DWM API to set the title bar to use a dark color. Here, you create a BOOL called value and set it to TRUE. This BOOL is used to trigger this Windows attribute setting. Then, you use DwmSetWindowAttribute to change the window attribute to use Dark mode colors.

    C++
    BOOL value = TRUE;
    ::DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
    Here's more explanation of what this call does.

    The syntax block for DwmSetWindowAttribute looks like this.

    C++
    HRESULT DwmSetWindowAttribute(
    HWND hwnd,
    DWORD dwAttribute,
    [in] LPCVOID pvAttribute,
    DWORD cbAttribute
    );
    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.

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

    绘制深色窗口标题栏的代码应如下所示。

    C++
    #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
    #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
    #万一


    BOOL InitInstance(HINSTANCE hInstance,int nCmdShow)
    {
    hInst = h实例;// 将实例句柄存储在我们的全局变量中

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

    布尔值 = 真;
    : :DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));

    如果(!hWnd)
    {
    返回假;
    }

    ShowWindow(hWnd, nCmdShow);
    更新窗口(hWnd);

    返回真;
    }
    运行此代码时,应用程序标题栏应该是黑色的:

     
  48. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    This is the way how to

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

    Know when Dark mode is enabled
    The first step is to keep track of the color mode setting itself. This will let you adjust your application's painting and rendering code to use a Dark mode color set. Doing this requires the app to read the color setting at startup and to know when the color setting changes during an app session.

    To do this in a Win32 application, use Windows::UI::Color and detect if a color can be classified as light or dark. To use Windows::UI::Color, you need to import (in pch.h) the Windows.UI.ViewManagement header from winrt.

    C++

    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">#include <winrt/Windows.UI.ViewManagement.h>
    Also include that namespace in main.cpp.

    C++
    using namespace Windows::UI::ViewManagement;
    In main.cpp, use this function to detect if a color can be classified as light.

    C++
    (8 * 128));
    }
    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">inline bool IsColorLight(Windows::UI::Color& clr)
    {
    return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
    }
    This function performs a quick calculation of the perceived brightness of a color, and takes into consideration ways that different channels in an RGB color value contribute to how bright it looks to the human eye. It uses all-integer math for speed on typical CPUs.

    Note

    This is not a model for real analysis of color brightness. It is good for quick calculations that require you to determine if a color can be classified as light or dark. Theme colors can often be light but not pure white, or dark but not pure black.

    Now that you have a function to check whether a color is light, you can use that function to detect if Dark mode is enabled.

    Dark mode is defined as a dark background with a contrasting light foreground. Since IsColorLight checks if a color is considered light, you can use that function to see if the foreground is light. If the foreground is light, then Dark mode is enabled.

    To do this, you need to get the UI color type of the foreground from the system settings. Use this code in main.cpp.

    C++
    auto settings = UISettings();

    auto foreground = settings.GetColorValue(UIColorType::Foreground);
    UISettings gets all the settings of the UI including color. Call UISettings.GetColorValue(UIColorType::Foreground) to get the foreground color value from the UI settings.

    Now you can run a check to see if the foreground is considered light (in main.cpp).

    C++
    (IsColorLight(foreground));

    wprintf(L"\nisDarkMode: %u\n", isDarkMode);
    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">bool isDarkMode = static_cast<bool>(IsColorLight(foreground));

    wprintf(L"\nisDarkMode: %u\n", isDarkMode);
    • If the foreground is light, then isDarkMode will evaluate to 1 (true) meaning Dark mode is enabled.
    • If the foreground is dark, then isDarkMode will evaluate to 0 (false) meaning Dark mode is not enabled.
    To automatically track when the Dark mode setting changes during an app session, you can wrap your checks like this.

    C++
    (IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast<bool>(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    Your full code should look like this.

    C++
    (8 * 128));
    }

    int main()
    {
    init_apartment();

    auto settings = UISettings();
    auto foreground = settings.GetColorValue(UIColorType::Foreground);

    bool isDarkMode = static_cast(IsColorLight(foreground));
    wprintf(L"\nisDarkMode: %u\n", isDarkMode);

    auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    static bool s_go = true;
    while (s_go)
    {
    Sleep(50);
    }
    }
    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">inline bool IsColorLight(Windows::UI::Color& clr)
    {
    return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128));
    }

    int main()
    {
    init_apartment();

    auto settings = UISettings();
    auto foreground = settings.GetColorValue(UIColorType::Foreground);

    bool isDarkMode = static_cast<bool>(IsColorLight(foreground));
    wprintf(L"\nisDarkMode: %u\n", isDarkMode);

    auto revoker = settings.ColorValuesChanged([settings](auto&&...)
    {
    auto foregroundRevoker = settings.GetColorValue(UIColorType::Foreground);
    bool isDarkModeRevoker = static_cast<bool>(IsColorLight(foregroundRevoker));
    wprintf(L"isDarkModeRevoker: %d\n", isDarkModeRevoker);
    });

    static bool s_go = true;
    while (s_go)
    {
    Sleep(50);
    }
    }
    When this code is run:

    If Dark mode is enabled, isDarkMode will evaluate to 1.



    Changing the setting from Dark mode to Light mode will make isDarkModeRevoker evaluate to 0.



    Enable a Dark mode title bar for Win32 applications
    Windows doesn't know if an application can support Dark mode, so it assumes that it can't for backwards compatibility reasons. Some Windows development frameworks, such as Windows App SDK, support Dark mode natively and change certain UI elements without any additional code. Win32 apps often don't support Dark mode, so Windows gives Win32 apps a light title bar by default.

    However, for any app that uses the standard Windows title bar, you can enable the dark version of the title bar when the system is in Dark mode. 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.

    C++
    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.

    C++

    " style="box-sizing: inherit; outline-color: inherit; font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 1em; direction: ltr; border: 0px; padding: 0px; line-height: 1.3571; display: block; position: relative;">#include <dwmapi.h>
    Then, define the DWMWA_USE_IMMERSIVE_DARK_MODE macros above your InitInstance function.

    C++
    #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
    #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
    #endif

    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {

    Finally, you can use the DWM API to set the title bar to use a dark color. Here, you create a BOOL called value and set it to TRUE. This BOOL is used to trigger this Windows attribute setting. Then, you use DwmSetWindowAttribute to change the window attribute to use Dark mode colors.

    C++
    BOOL value = TRUE;
    ::DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
    Here's more explanation of what this call does.

    The syntax block for DwmSetWindowAttribute looks like this.

    C++
    HRESULT DwmSetWindowAttribute(
    HWND hwnd,
    DWORD dwAttribute,
    [in] LPCVOID pvAttribute,
    DWORD cbAttribute
    );
    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.

    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.

    C++
    #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;
    ::DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));

    if (!hWnd)
    {
    return FALSE;
    }

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

    return TRUE;
    }
    When this code is run, the app title bar should be dark:

     
  49. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Lol that's a long post for a wrong thing. Unity's title bar is already dark but menu isn't. Your screenshot also doesn't have menu items dark
     
  50. Shompinice

    Shompinice

    Joined:
    May 7, 2022
    Posts:
    19
    I have installed 2023 but its title bar is white still?Could you please share a screenshot?