[英]Delphi: Draw a text in a caption form for vista with aero like windows 7
How does one draw text (with onClick event) in a caption bar on vista with aero Like Windows 7 ? 如何使用aero Like Windows 7在vista的标题栏中绘制文本(使用onClick事件)?
alt text http://img529.imageshack.us/img529/3643/immaginembl.jpg 替代文字http://img529.imageshack.us/img529/3643/immaginembl.jpg
The example at delphi.about.com doesn't work on Vista with aero. delphi.about.com上的示例无法在带有aero的Vista上运行。 Do you have any ideas?
你有什么想法?
Thanks to all. 谢谢大家。
Sorry for my bad english. 对不起,我的英语不好。
Drawing in the nonclient region causes glass to be disabled automatically. 在非客户区域中绘图会导致玻璃自动禁用。 What MS Office does is expand the client region to cover the borders.
MS Office所做的是扩展客户区域以覆盖边界。 Look at the "Drawing in the NC area with glass" section of this WPF article for suggestions.
请查看此WPF文章中的“在玻璃的NC区域绘图”部分以获取建议。 You'll have to convert the API calls to Delphi yourself, I'm afraid.
你担心,你必须自己将API调用转换为Delphi。
The key is the API DwmExtendFrameIntoClientArea 关键是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 您还可以在此处移植代码: 带有Aero的半透明Windows
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. 有了这一切,不应该很难实现你想要的。
Extending the frame is one thing and drawing Vista themed (glowing) text is another. 扩展框架是一回事,绘制Vista主题(发光)文本是另一回事。 With Canvas.TextOut or DrawText the output has messed up alpha which will give the effect you got.
使用Canvas.TextOut或DrawText,输出已经搞砸了alpha,这将产生你得到的效果。 You need to use DrawThemeTextEx.
您需要使用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;
Thanks for DrawTextOnGlass code. 感谢DrawTextOnGlass代码。 But to work as expected, I needed to replace
b.handle
b.canvas.handle
in DrawThemeTextEx
但是为了按预期工作,我需要在
DrawThemeTextEx
替换b.handle
b.canvas.handle
You need a single call to DwmSetWindowAttribute, after that everything is quite simple. 你需要一次调用DwmSetWindowAttribute,之后一切都很简单。 Check this article and especially comments :) http://delphihaven.wordpress.com/2010/04/22/setting-up-a-custom-title-bar-reprise/
查看这篇文章,特别是评论:) http://delphihaven.wordpress.com/2010/04/22/setting-up-a-custom-title-bar-reprise/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.