Nir的答案是正确的;当禁用组合时,您必须自己绘制该区域。
我可以向您展示我在窗体顶部面板的绘制处理程序中拥有的代码 - 该面板通常负责绘制0x00000000透明黑色以使玻璃出现:
伪代码:
procedure DrawGlassHeaderArea(g: Graphics; r: Rectangle; IsFormFocused: Boolean);
const
clFakeGlassColor = $00EAD1B9;
clFakeGlassColorUnfocused = $00F2E4D7;
begin
if Dwm.IsCompositionEnabled then
begin
g.FillRectangle(r, 0x00000000);
end
else
Color glassColor;
if (IsFormFocused) then
c = clFakeGlassColor
else
c = clFakeGlassColorUnfocused;
g.FillRectangle(r, glassColor);
Color edgeHighlight = ColorBlend(Colors.White, glassColor, 0.33);
Color edgeShadow = ColorBlend(Colors.Black, glassColor, 0.33);
g.DrawLine(edgeHighlight, Point(r.Left, r.Bottom-2), Point(r.Right, r.Bottom-2);
g.DrawLine(edgeHighlight, Point(r.Left, r.Bottom-1), Point(r.Right, r.Bottom-1);
end;
end;
使用示例
procedure MyForm.PaintBox1Paint(PaintEventArgs e)
begin
DrawGlassHeaderArea(e.Graphics, PaintBox1.ClientRectangle, this.HasFocus);
end;
奖励截图
![enter image description here](https://istack.dev59.com/YOWwQ.webp)
2014年7月9日更新
@JakePetroules是对的,我错了。用于虚假玻璃的"蓝色"并没有硬编码到Windows中。而且可以使用GetThemeColor
访问。
我编写了所有可用颜色(TMT_COLOR
)的代码,这些颜色适用于Window类:
![enter image description here](https://istack.dev59.com/exmsy.webp)
注意:有关类、部件和状态的更多信息,请参见Aero样式类、部件和状态
当使用:
- 类:
Window
- 部件:
WP_CAPTION
- 状态: n/a (StateID未用于Caption部件,也未用于整个Window类)
并获取颜色代码propertyID:
TMT_FILLCOLORHINT
: 当窗口具有焦点时
TMT_BORDERCOLORHINT
: 当窗口没有焦点时
您将获得两个重要的颜色:
![enter image description here](https://istack.dev59.com/1D7Xd.webp)
我现在使用的伪代码来获取虚假玻璃颜色:
public Color GetFakeClassColor(Boolean isWindowFocused=true)
{
static Color fakeGlass= 0x00B8D0E9;
if ((GetThemeAppProperties() && STAP_ALLOW_CONTROLS) == 0)
return fakeGlass;
hTheme = OpenThemeData(GetDesktopWindow(), "Window");
if (hTheme = 0)
return fakeGlass;
Int32 propID;
if (isWindowFocused)
propID= TMT_FILLCOLORHINT;
else
propID= TMT_BORDERCOLORHINT;
DWORD rgb;
if (Failed(GetThemeColor(hTheme, WP_CAPTION, 0, propID, ref rgb))
return fakeGlass;
Result = new Color(rgb);
}
实际上,由于我使用Delphi,我的实际代码如下:
function GetFakeGlassColor(IsWindowFocused: Boolean=True): TColor;
var
ted: TThemedElement;
hTheme: THandle;
propID: Integer;
rgb: DWORD;
begin
Result := $00B8D0E9;
if not ThemeServices.ThemesAvailable then
Exit;
if (GetThemeAppProperties and STAP_ALLOW_CONTROLS) = 0 then
Exit;
htheme := ThemeServices.Theme[teWindow];
if hTheme = 0 then
Exit;
if IsWindowFocused then
propID := TMT_FILLCOLORHINT
else
propID := TMT_BORDERCOLORHINT;
if Failed(GetThemeColor(hTheme, WP_CAPTION, 0, propID, rgb)) then
Exit;
Result := rgb;
end;
ColorBlend
只是执行color1*(1-mix) + color2*(mix)
(mix=0 ==> 纯色1,mix=1.0 ==> 纯色2)。 - Ian Boyd