Ale*_*lex 11 .net c# wpf aero dwm
使用DwmExtendFrameIntoClientArea启用Aero Glass 的API调用可以正常工作.但是,我希望它也可以在Aero Glass被禁用时工作,就像它在Windows控制面板中的工作方式一样:

注意框架是如何扩展到客户区的,即使Aero Glass被禁用了?当我DwmExtendFrameIntoClientArea在我的应用程序中进行API调用时,返回的HRESULT肯定不成功,我的应用程序最终看起来像这样:
http://img197.imageshack.us/img197/9629/clientapplication.png
通常,启用Aero Glass后,边框会向下延伸到导航按钮下方,就像在控制面板中一样.我该怎么做呢?DwmExtendFrameIntoClientArea显然不起作用.
顺便说一句,如果它是相关的,我的应用程序是一个WPF应用程序.
尼尔的回答是正确的; 当组合被禁用时,你必须自己绘制该区域.
我可以向我展示我在表单顶部的面板的绘制处理程序中的代码 - 通常负责绘制0x00000000透明黑色以使玻璃显示的面板:
procedure DrawGlassHeaderArea(g: Graphics; r: Rectangle; IsFormFocused: Boolean);
const
clFakeGlassColor = $00EAD1B9; //(185, 209, 234) This is the fake foreground glass color (for use when composition is disabled)
clFakeGlassColorUnfocused = $00F2E4D7; //(215, 228, 242) This is the fake background glass color (for use when composition is disabled)
begin
if Dwm.IsCompositionEnabled then
begin
g.FillRectangle(r, 0x00000000); //fill rectangle with transparent black
end
else
//Composition disabled; fake it like Microsoft does
//The color to use depends if the form has focused or not
Color glassColor;
if (IsFormFocused) then
c = clFakeGlassColor
else
c = clFakeGlassColorUnfocused;
g.FillRectangle(r, glassColor); //fill rectangle with fake color
//Now we have to draw the two accent lines along the bottom
Color edgeHighlight = ColorBlend(Colors.White, glassColor, 0.33); //mix 33% of glass color to white
Color edgeShadow = ColorBlend(Colors.Black, glassColor, 0.33); //mix 33% of glass color to black
//Draw highlight as 2nd-last row:
g.DrawLine(edgeHighlight, Point(r.Left, r.Bottom-2), Point(r.Right, r.Bottom-2);
//Draw shadow on the very last row:
g.DrawLine(edgeHighlight, Point(r.Left, r.Bottom-1), Point(r.Right, r.Bottom-1);
end;
end;
Run Code Online (Sandbox Code Playgroud)
procedure MyForm.PaintBox1Paint(PaintEventArgs e)
begin
DrawGlassHeaderArea(e.Graphics, PaintBox1.ClientRectangle, this.HasFocus);
end;
Run Code Online (Sandbox Code Playgroud)

@JakePetroules是对的,我错了.用于假玻璃的"蓝色" 不是硬编码到Windows中.它是利用访问GetThemeColor.
我编写了TMT_COLOR可用于Window类的所有可用颜色():

注意:有关类,部件和状态的详细信息,请参阅Aero样式类,部件和状态
使用时:
WindowWP_CAPTION并获取颜色代码propertyID:
TMT_FILLCOLORHINT:当窗口具有焦点时TMT_BORDERCOLORHINT:当窗口没有焦点时你得到两个重要的颜色:

我现在使用伪代码来获取假玻璃颜色:
public Color GetFakeClassColor(Boolean isWindowFocused=true)
{
static Color fakeGlass= 0x00B8D0E9; //the correct answer anyway
if ((GetThemeAppProperties() && STAP_ALLOW_CONTROLS) == 0)
return fakeGlass;
hTheme = OpenThemeData(GetDesktopWindow(), "Window");
if (hTheme = 0)
return fakeGlass;
Int32 propID;
if (isWindowFocused)
propID= TMT_FILLCOLORHINT; //The color used as a fill color hint for custom controls.
else
propID= TMT_BORDERCOLORHINT; //The color used as a border color hint for custom controls.
DWORD rgb;
if (Failed(GetThemeColor(hTheme, WP_CAPTION, 0, propID, ref rgb))
return fakeGlass;
Result = new Color(rgb);
}
Run Code Online (Sandbox Code Playgroud)
实际上,因为我使用Delphi,我的实际代码是:
function GetFakeGlassColor(IsWindowFocused: Boolean=True): TColor;
var
ted: TThemedElement;
hTheme: THandle;
propID: Integer;
rgb: DWORD;
begin
Result := $00B8D0E9; //the correct answer anyway
//We can't use the ThemeServcies.ThemesEnabled, as that mistakenly checks for version 6 of the common controls library
//Themes can be enabled without using ComCtl V6, or common controls at all
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 //The color used as a fill color hint for custom controls.
else
propID := TMT_BORDERCOLORHINT; //The color used as a border color hint for custom controls.
if Failed(GetThemeColor(hTheme, WP_CAPTION, 0, propID, {var}rgb)) then
Exit;
Result := rgb;
end;
Run Code Online (Sandbox Code Playgroud)
你必须把它画成你自己的框架。
您必须使用DwmIsCompositionEnabled检查 DWM 是否启用并处理WM_DWMCOMPOSITIONCHANGED来检测 DWM 状态更改。
然后你必须以单独的方式绘制窗口,如果启用了 DWM,则使用DwmExtendFrameIntoClientArea,如果禁用,则自己绘制“框架”。
我不知道如何在 WPF 中复制 Aero 框架(在我的应用程序中,我有自己的配色方案,并且没有使用 Auro 框架)。
这很烦人,但是当 DWM 被禁用时,系统会回退到 XP 样式绘图,并且 DWM 的任何服务都不起作用 - 即使是那些与玻璃效果无关的服务。