gpt4 book ai didi

c# - 没有 Aero Glass 的 DwmExtendFrameIntoClientArea

转载 作者:可可西里 更新时间:2023-11-01 08:44:42 36 4
gpt4 key购买 nike

在启用 Aero Glass 的情况下使用 DwmExtendFrameIntoClientArea API 调用效果很好。但是,我希望它在禁用 Aero Glass 时也能正常工作,就像它在 Windows 控制面板中的工作方式一样:

enter image description here

注意框架如何延伸到客户区,即使 Aero Glass 被禁用?当我在我的应用程序中调用 DwmExtendFrameIntoClientArea API 时,返回的 HRESULT 绝对不成功,我的应用程序最终看起来像这样:

http://img197.imageshack.us/img197/9629/clientapplication.png

通常情况下,启用 Aero Glass 后,边框会向下延伸到导航按钮下方,就像在控制面板中一样。我该怎么做呢? DwmExtendFrameIntoClientArea 显然不起作用。

顺便说一下,如果相关的话,我的应用程序是一个 WPF 应用程序。

最佳答案

Nir 的回答是正确的;当合成被禁用时,你必须自己绘制那个区域。

我可以向您展示我在表单顶部面板的绘制处理程序中的代码 - 该面板通常负责绘制 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;

示例用法

procedure MyForm.PaintBox1Paint(PaintEventArgs e)
begin
DrawGlassHeaderArea(e.Graphics, PaintBox1.ClientRectangle, this.HasFocus);
end;

奖金截图

enter image description here

2014 年 7 月 9 日更新

@JakePetroules 是对的,我错了。用于假玻璃的“蓝色”硬编码到 Windows 中。它可以使用 GetThemeColor 访问.

我编写了可用于 Window 类的所有可用颜色 (TMT_COLOR):

enter image description here

Note: For more information about Classes, Parts, and States, see Aero Style Classes, Parts, and States

使用时:

  • :窗口
  • 部分:WP_CAPTION
  • State:n/a(StateID 未用于Caption 部分,也未用于整个Window 类)

并获取颜色代码propertyID:

  • TMT_FILLCOLORHINT:当窗口有焦点时
  • TMT_BORDERCOLORHINT:当窗口没有焦点时

你得到了两种重要的颜色:

enter image description here

我现在用来获取假玻璃颜色的伪代码:

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);
}

实际上,因为我使用 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;

关于c# - 没有 Aero Glass 的 DwmExtendFrameIntoClientArea,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2235845/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com