使用GDI +绘制各种颜色:
brush = new SolidBrush(color);
graphics.FillRectangle(brush, x, y, width, height);
Run Code Online (Sandbox Code Playgroud)
您会注意到在玻璃上没有显示不透明的颜色:

我如何在玻璃上画出纯色?
您还会注意到完全不透明的颜色会根据颜色的不同而有所不同:

有人能指出我在桌面合成器上的文档,解释了如何处理不同的颜色?
您还会注意到FillRectangle行为与以下不同FillEllipse:
FillEllipse 不透明的颜色会产生不透明的颜色FillRectangle 不透明的颜色部分(或完全)透明
请解释非感性行为.
Alwayslearning建议我改变合成模式.来自MSDN:
CompositingMode枚举
该CompositingMode枚举指定如何呈现的颜色与背景颜色组合.此枚举由使用
Graphics::GetCompositingMode和"图形:: SetCompositingMode"的方法图形类.Run Code Online (Sandbox Code Playgroud)CompositingModeSourceOver指定在渲染颜色时,它与背景颜色混合.混合由要渲染的颜色的alpha分量确定.
Run Code Online (Sandbox Code Playgroud)CompositingModeSourceCopy指定在渲染颜色时,它会覆盖背景颜色.此模式不能与TextRenderingHintClearTypeGridFit一起使用.
从描述来看CompositingModeSourceCopy,听起来这不是我想要的选择.从它所施加的限制来看,它听起来像我想要的选项.并且通过禁用合成或透明度,它不是我想要的选项,因为它执行SourceCopy而不是SourceBlend:

幸运的是,这不是一个我必须考虑的邪恶,因为它不能解决我的实际问题.构建我的graphics对象后,我尝试更改合成模式:
graphics = new Graphics(hDC);
graphics.SetCompositingMode(CompositingModeSourceCopy); //CompositingModeSourceCopy = 1
Run Code Online (Sandbox Code Playgroud)
结果对输出没有影响:

我必须在客户区涂上什么颜色才能制作玻璃?
我使用以下方法将表单框架扩展到客户区:
DwmExtendFrameIntoClientArea(self.Handle, margins);
Run Code Online (Sandbox Code Playgroud)
我找不到微软的官方文档,说明DWM用玻璃代替什么颜色和/或alpha.DwmExtendFrameInClientArea上的文档甚至没有提到需要自定义颜色.只有传闻和神话,甚至需要特殊的颜色.
我能找到的最接近的是MSDN上的主题:
使用DWM的自定义窗口框架
为了使扩展帧可见,每个扩展帧的边下面的区域必须具有alpha值为0的像素数据.
更新:和博客文章:
Windows Vista for Developers - 第3部分 - 桌面窗口管理器
碰巧RGB黑色(0x00000000)的位模式与100%透明ARGB的位模式相同,因此您可以使用"黑色"GDI画笔实际绘制并假设您已指示DWM模糊绘制区域,结果将是所需的玻璃效果.
如果我按照他们的字面意思(alpha值为零的像素数据),我构造一个零alpha的颜色,并在扩展区域绘制:
Color fillColor = Color.FromArgb(0, 0, 0, 0); //(a, r, g, b)
e.Graphics.FillRectangle(new SolidBrush(fillColor), e.ClipRectangle);
Run Code Online (Sandbox Code Playgroud)
但玻璃效果没有出现:
替代文字http://i46.tinypic.com/anlmd4.png
如果我忽略引用的MSDN主题,而是使用完全不透明的黑色(而不是完全透明的黑色):
Color fillColor = Color.FromArgb(255, 0, 0, 0); //(a, r, g, b)
e.Graphics.FillRectangle(new SolidBrush(fillColor), e.ClipRectangle);
Run Code Online (Sandbox Code Playgroud)
玻璃效果确实出现了:
alt text http://i45.tinypic.com/2ug2ias.png
然后我开始相信不透明的黑色是DWM用玻璃代替的像素值.
但那我如何在玻璃区域上画黑色物品呢?
我测试过在玻璃区域上画一个黑色矩形,旁边有一个圆圈.奇怪的是,矩形没有出现,而圆圈确实出现; 两者颜色相同:
Brush …Run Code Online (Sandbox Code Playgroud) 我正在对TIceTabSet(Chrome标签)组件进行多次更新.其中一项变化是增加透明度.除了文本之外,一切都很好.随着背景的alpha通道变低,文本变得越来越模糊.这是一个截图.

这是绘制标签的代码.其中大部分是原始的TIceTabSet代码.我只是添加了一些更改以使标签透明.对于示例屏幕截图,代码也进行了一些修改.底部的DrawText命令是将文本绘制到画布的位置.
procedure TIceTabSet.InnerDraw(Canvas: TCanvas; TabRect: TRect; Item: TIceTab);
var
graphics : TGPGraphics;
Pen: TGPPen;
Brush: TGPSolidBrush;
path, linePath: TGPGraphicsPath;
linGrBrush: TGPLinearGradientBrush;
font: TGPFont;
solidBrush: TGPSolidBrush;
rectF: TGPRectF;
stringFormat: TGPStringFormat;
DC: HDC;
marginRight: integer;
iconY, iconX: integer;
textStart: Extended;
startColor, EndColor, textColor, borderColor: cardinal;
borderWidth: Integer;
TabProperties: TIceTabProperties;
Alpha: Byte;
begin
DC := Canvas.Handle;
TabProperties := GetTabProperties(Item);
Alpha := Item.Index * 50;
startColor := MakeGDIPColor(TabProperties.TabStyle.StartColor, Alpha);// TabProperties.TabStyle.Alpha);
endColor := MakeGDIPColor(TabProperties.TabStyle.StopColor, Alpha); //TabProperties.TabStyle.Alpha);
textColor := MakeGDIPColor(TabProperties.Font.Color, 255); //TabProperties.TabStyle.Alpha);
borderColor := MakeGDIPColor(TabProperties.BorderColor, …Run Code Online (Sandbox Code Playgroud)