在Win32应用程序中模仿丙烯酸 [英] Mimicking Acrylic in a Win32 app

查看:123
本文介绍了在Win32应用程序中模仿丙烯酸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Microsoft最近宣布丙烯酸,Fluent Design中的玻璃状材料.它仅以XAML/UWP的形式呈现,但外观与玻璃非常相似,不同之处在于它可以随意着色,并且可以将应用内应用程序应用于跨接控件以及应用程序的独立窗口.

Microsoft recently announced Acrylic, the glass-like material in Fluent Design. It's presented as XAML / UWP only, but looks very similar to glass, except it can be arbitrarily tinted and can apply in-app to flyover controls as well as to the app's standalone windows.

食谱"使它看起来像是

The 'recipe' makes it appear as though it's implemented in XAML itself, not being exposed to the wider system.

一个相关的SO问题确认(它没有具体的技术答案,但暗示丙烯酸不能像玻璃一样通过WinAPI使用.)

A related SO question confirms this (it's devoid of concrete, technical answers, but implies acrylic isn't available through the WinAPI the way glass is.)

有人会如何在普通的旧版Win32应用程序中模仿这一点?是使用玻璃杯进行混合吗? (哪些API和 Win10秋季可能发生什么更新的Glass API不在Win7中吗?)如果该应用是使用Win32创建的,但使用DirectX曲面进行渲染,那么它将打开更多的可能性吗?

How would someone mimic this in a plain old Win32 app? Using glass, and blending? (Which APIs, and what's possible in Win10 Fall Update's glass APIs that was not in Win7?) If the app was created with Win32 but used a DirectX surface for rendering, would it open more possibilities?

推荐答案

正如@ zett42的答案中所述,我认为它是使用DirectComposition实现的.

As mentioned in @zett42's answer, I think it is implemented using DirectComposition.

一段历史:Microsoft在Vista中引入了Desktop Window Manager DWM,它是Desktop的合成引擎.使用DWM,窗口将绘制为纹理,然后将其合并到DWM中.好处是您可以获得奇特的效果,例如3D动画,透明度等,并且所有内容都是双缓冲的,因此您不会得到任何渲染瑕疵.

A little bit of history: With Vista, Microsoft introduced the Desktop Window Manager, DWM, which is a compositing engine for the Desktop. With DWM, windows draw to textures, which are then combined in the DWM. The benefits are that you can get fancy effects like 3D animations, transparency, etc. and everything is double-buffered, so you get no rendering artifacts.

DWM最初基于MIL(媒体集成层),我认为这是一个场景图API.有趣的是,大约在那时引入的WPF也使用了MIL.这真的很酷,因为DWM可以看到WPF窗口的场景图,并且当它产生效果(例如放大窗口)时,它会将其视为矢量而不是位图,因此可以缩放它而没有伪像.但是,在某个时候,Microsoft分叉了WPF中使用的MIL版本,并且此集成丢失了.

The DWM originally was based on MIL (Media integration layer), which was a scenegraph API I think. Interestingly, WPF which was introduced around that time also used MIL. This was really cool because DWM could see the scene graph of a WPF window, and when it would so effects, such as zooming in a window, it would see it as vectors and not as a bitmap, so it could scale it without artifacts. However, at some point Microsoft forked the version of MIL used in WPF, and this integration was lost.

将Windows 8快进几年.Microsoft引入了新的"Metro"应用程序(后来的"Modern"和现在的"UWP").在后台,这些现代应用程序使用新的API进行合成,即DirectComposition.此API也可用于Win32应用程序,并且现在由DWM本身使用.如果您查看公共DWM功能,则不赞成使用某些与MIL相关的功能,因此它支持我的理论,即MS从MIL转向DC.因此,现在我们又回到了最初的状态,即应用程序和DWM使用相同的基础结构,我们可以轻松地添加一些有趣的效果.

Fast forward a few years to Windows 8. Microsoft introduced new "Metro" apps (later "Modern", and now "UWP"). Under the hood, these modern apps use a new API for composition, DirectComposition. This API is also available to Win32 apps, and it is now used by DWM itself. If you look at the public DWM functions, some related to MIL are deprecated, so it supports my theory that MS moved away from MIL and towards DC. So now that we are in the initial situation again where apps as well as the DWM use the same infrastructure, we can easily add some interesting effects.

在某些时候,MS已将DirectComposition引入了新的混合效果,由

At some point, MS has introduced new blending effects to DirectComposition, provided by the IDCompositionDevice3 interface. Among those is a gaussan blur effect, but also noise, tint, and other effects neccessary. I found a way to apply these effects within my window, but I don't know how to apply them to my window. Unfortunately, I don't have access to my code right now, I'll update my answer when I do.

我的探索基于文章高效的Alpha混合Windows:DirectComposition .基本上,您有一个与屏幕相对应的设备",以及一个与窗口内容相对应的可视".您需要更改的是:

I based my exploration on the article Efficient Alpha-Blended Windows: DirectComposition. Basically, you have a "Device" corresponding to the screen, and a "Visual" corresponding your window contents. What you have to change is:

  • 您的设备可以为您创建效果.请记住将其QueryInterface更改为IDCompositionDevice3.
  • 然后,您可以在IDCompositionVisual3上调用SetEffect.
  • Your Device can create Effects for you. Remember to QueryInterface it to IDCompositionDevice3.
  • Then, you can call SetEffect on your IDCompositionVisual3.

但是,正如我所说,这仅适用于窗口内容.我认为必须有一个秘密API,才能从DWM将父Visual移到当前窗口,然后只需在该Visual上调用SetEffect即可获得效果.如果有人熟练使用调试器,则应该可以通过跟踪使用了Acyllic效果的UWP应用找到该API.

However, as I said, this only applies to the window contents. I think there must be a secret API to get a parent Visual to the current window from the DWM, and then it should be just a matter of calling SetEffect on that Visual to get the effect. If somebody is skilled with a debugger, it should be possible to find that API by tracing a UWP app that uses the Acyllic effect.

作为蓝色的镜头,我将看一下GetWindowCompositionAttribute函数.它最近获得了一些有趣的声音标记,例如WCA_VISUAL_OWNER.

As a shot in the blue, I would look at the GetWindowCompositionAttribute function. It recently gained some interesting sounding flags, such as WCA_VISUAL_OWNER.

这篇关于在Win32应用程序中模仿丙烯酸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆