Delphi:在 vista 和 aero 中以标题形式绘制文本,如 windows 7

发布于 2024-07-29 06:08:48 字数 406 浏览 7 评论 0 原文

如何在 vista 上使用 aero 像 Windows 7 一样在标题栏中绘制文本(使用 onClick 事件)?

替代文本 http://img529.imageshack.us/img529/3643/immaginembl.jpg< /a>

delphi.about.com 中的示例不适用于带有 aero 的 Vista。 你有什么想法?

谢谢大家。

对不起,我的英语不好。

How does one draw text (with onClick event) in a caption bar on vista with aero Like Windows 7 ?

alt text http://img529.imageshack.us/img529/3643/immaginembl.jpg

The example at delphi.about.com doesn't work on Vista with aero. Do you have any ideas?

Thanks to all.

Sorry for my bad english.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情未る 2024-08-05 06:08:48

在非客户区域绘图会导致玻璃自动禁用。 MS Office 所做的就是扩大客户区域以覆盖边界。 请查看 这篇 WPF 文章 获取建议。 恐怕您必须自己将 API 调用转换为 Delphi。

Drawing in the nonclient region causes glass to be disabled automatically. What MS Office does is expand the client region to cover the borders. Look at the "Drawing in the NC area with glass" section of this WPF article for suggestions. You'll have to convert the API calls to Delphi yourself, I'm afraid.

二智少女猫性小仙女 2024-08-05 06:08:48

关键是 API DwmExtendFrameIntoClientArea

你应该声明并像这样得到它:

DwmExtendFrameIntoClientAreaFunc = function(destWnd: HWND; const pMarInset: PMargins): HRESULT; stdcall; 
@fDwmExtendFrameIntoClientArea := GetProcAddress(hDWMDLL, 'DwmExtendFrameIntoClientArea'); 

您还已经将代码移植到这里: 带 Aero 的半透明窗口

没有框架,您这样称呼它:

DWM_ExtendFrameIntoClientArea(Form1.Handle, -1, -1, -1, -1);

有了这一切,实现您想要的应该不难。

The key is the API DwmExtendFrameIntoClientArea

You shoud declare it and get it like this:

DwmExtendFrameIntoClientAreaFunc = function(destWnd: HWND; const pMarInset: PMargins): HRESULT; stdcall; 
@fDwmExtendFrameIntoClientArea := GetProcAddress(hDWMDLL, 'DwmExtendFrameIntoClientArea'); 

You also have the code already ported here: Translucent Windows with Aero

To have not frame you call it like:

DWM_ExtendFrameIntoClientArea(Form1.Handle, -1, -1, -1, -1);

With all this it should not be to hard to achieve what you want.

两个我 2024-08-05 06:08:48

在 Delphi 2009 中,TLabel 有一个名为“GlowSize”的新属性(查看帮助)。 为此属性设置正值的效果非常接近您似乎正在寻找的效果(标签文本周围的发光)。

In Delphi 2009 TLabel has a new property called "GlowSize" (see help). The effect of setting a positive value for this property is very close to what you seem to be looking for (a glow around label's text).

欲拥i 2024-08-05 06:08:48

您需要对 DwmSetWindowAttribute 进行一次调用,之后一切都非常简单。 检查这篇文章,特别是评论:) http://delphihaven.wordpress.com/2010/04/22/setting-up-a-custom-title-bar-reprise/

You need a single call to DwmSetWindowAttribute, after that everything is quite simple. Check this article and especially comments :) http://delphihaven.wordpress.com/2010/04/22/setting-up-a-custom-title-bar-reprise/

眼泪淡了忧伤 2024-08-05 06:08:48

扩展框架是一回事,绘制 Vista 主题(发光)文本是另一回事。 使用 Canvas.TextOut 或 DrawText 时,输出会弄乱 alpha,这将给您带来效果。 您需要使用 DrawThemeTextEx。 以下是在玻璃上绘制文字的正确步骤:

uses Themes, UxTheme;

procedure DrawTextOnGlass(Canvas: TCanvas; Text: String; R: TRect);
var
  memoryHdc: HDC;
  b: TBitmap;
  dttOpts: TDTTOpts;
  DR: TRect;
  bf: TBlendFunction;
begin
  b := TBitmap.Create;
  try
    memoryHdc := CreateCompatibleDC(Canvas.Handle);

    b.Handle := memoryHdc;
    b.HandleType := bmDIB;
    b.PixelFormat := pf32bit;
    b.SetSize(R.Right - R.Left, R.Top - R.Bottom);
    b.Canvas.Font := Canvas.Font;

    DR := R;
    OffsetRect(DR, -DR.Left, -DR.Top);
    Inflaterect(dr, -5, -5);
    b.Canvas.Brush.Color := clBlack;
    b.Canvas.FillRect(DR);

    dttOpts.dwSize := SizeOf(TDTTOpts);
    dttOpts.iGlowSize := 8;
    dttOpts.dwFlags := DTT_COMPOSITED or DTT_GLOWSIZE or DTT_TEXTCOLOR;

    DrawThemeTextEx(ThemeServices.Theme[teWindow], b.Handle, WP_CAPTION, CS_ACTIVE, Text, -1,
      DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX, DR, dttOpts);
  if GetLastError <> 0 then
        RaiseLastOSError;


    bf.BlendOp := AC_SRC_OVER;
    bf.BlendFlags := 0;
    bf.SourceConstantAlpha := 255;
    bf.AlphaFormat := AC_SRC_ALPHA;

    AlphaBlend(Canvas.Handle, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
      b.Canvas.Handle, 0, 0, R.Right - R.Left, R.Bottom - R.Top, bf);
  finally
    b.Free;
  end;
end;

Extending the frame is one thing and drawing Vista themed (glowing) text is another. With Canvas.TextOut or DrawText the output has messed up alpha which will give the effect you got. You need to use DrawThemeTextEx. Heres the correct procedure for drawing text on glass:

uses Themes, UxTheme;

procedure DrawTextOnGlass(Canvas: TCanvas; Text: String; R: TRect);
var
  memoryHdc: HDC;
  b: TBitmap;
  dttOpts: TDTTOpts;
  DR: TRect;
  bf: TBlendFunction;
begin
  b := TBitmap.Create;
  try
    memoryHdc := CreateCompatibleDC(Canvas.Handle);

    b.Handle := memoryHdc;
    b.HandleType := bmDIB;
    b.PixelFormat := pf32bit;
    b.SetSize(R.Right - R.Left, R.Top - R.Bottom);
    b.Canvas.Font := Canvas.Font;

    DR := R;
    OffsetRect(DR, -DR.Left, -DR.Top);
    Inflaterect(dr, -5, -5);
    b.Canvas.Brush.Color := clBlack;
    b.Canvas.FillRect(DR);

    dttOpts.dwSize := SizeOf(TDTTOpts);
    dttOpts.iGlowSize := 8;
    dttOpts.dwFlags := DTT_COMPOSITED or DTT_GLOWSIZE or DTT_TEXTCOLOR;

    DrawThemeTextEx(ThemeServices.Theme[teWindow], b.Handle, WP_CAPTION, CS_ACTIVE, Text, -1,
      DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX, DR, dttOpts);
  if GetLastError <> 0 then
        RaiseLastOSError;


    bf.BlendOp := AC_SRC_OVER;
    bf.BlendFlags := 0;
    bf.SourceConstantAlpha := 255;
    bf.AlphaFormat := AC_SRC_ALPHA;

    AlphaBlend(Canvas.Handle, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
      b.Canvas.Handle, 0, 0, R.Right - R.Left, R.Bottom - R.Top, bf);
  finally
    b.Free;
  end;
end;
姜生凉生 2024-08-05 06:08:48

感谢您提供 DrawTextOnGlass 代码。 但为了按预期工作,我需要替换 DrawThemeTextEx 中的 b.handle b.canvas.handle

Thanks for DrawTextOnGlass code. But to work as expected, I needed to replace b.handle b.canvas.handle in DrawThemeTextEx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文