How do you set the glass blend colour on Windows 10?

前端 未结 3 1123
醉酒成梦
醉酒成梦 2020-11-30 20:49

Using the undocumented SetWindowCompositionAttribute API on Windows 10, it\'s possible to enable glass for a window. The glass is white or clear, as seen in this screenshot:

3条回答
  •  醉话见心
    2020-11-30 21:19

    AccentPolicy.GradientColor has effect when you play with AccentPolicy.AccentFlags, I found these values:

    • 2 - fills window with AccentPolicy.GradientColor - what you need
    • 4 - makes area to the right and bottom of the window blurred (weird)
    • 6 - combination of above: fills whole screen with AccentPolicy.GradientColor and blurs area like 4

    To set AccentPolicy.GradientColor property, you'll need ActiveCaption and InactiveCaption system colours. I would try Rafael's suggestion to use GetImmersiveColor* family of functions (see update). Also there is a question for Vista/7.

    Note: I tried drawing with GDI+ and saw that FillRectangle() works incorrectly with Glass when brush.alpha==0xFF (workarounds here). Inner rectangles have brush.alpha==0xFE on both screenshots because of this bug.

    Screenshots note: GradientColor==0x80804000, it doesn't have to be premultiplied, just a coincidence.

    Update: To get accent color, you can use C++/WinRT - it is a documented and thus preferred approach for Windows 10:

    #include  // may need "Microsoft.Windows.CppWinRT" NuGet package
    ...
    using namespace winrt::Windows::UI::ViewManagement;
    winrt::Windows::UI::Color accent = UISettings{}.GetColorValue(UIColorType::Accent);
    

提交回复
热议问题