适用于所有 Win32 程序员在 Windows Aero Glass(DWM、GDI、GDI+)上绘图的文档和 API 示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3822609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:20:01  来源:igfitidea点击:

Documentation and API Samples for drawing on Windows Aero Glass (DWM, GDI, GDI+) for all Win32 programmers

windowsdelphivisual-c++windows-7aero-glass

提问by Warren P

I am looking for good resources for learning to use the Win32/GDI APIs or whatever supercedes it to draw and paint directly using the Win32 API to a glass form.

我正在寻找学习使用 Win32/GDI API 或任何替代它以直接使用 Win32 API 绘制和绘制玻璃表单的好资源。

While I am using Delphi, I tagged this as Delphi or Visual C++. Any code samples and articles that you can find would be appreciated. MSDN articles do not seem to be written about this.

当我使用 Delphi 时,我将其标记为 Delphi 或 Visual C++。您能找到的任何代码示例和文章将不胜感激。MSDN 文章似乎没有写过这个。

As a goal, let's imagine you want to either: (a) Reproduce what Google Chrome does (tabs as part of the glass frame) (b) Reproduce what MS Office 2010 does (save button on the glass frame, referred to in MFC for VS 2010, as "Quick Access Toolbar" (see picture below).

作为一个目标,让我们假设您想要:(a) 重现 Google Chrome 的功能(标签作为玻璃框架的一部分) (b) 重现 MS Office 2010 的功能(玻璃框架上的保存按钮,在 MFC 中称为VS 2010,作为“快速访问工具栏”(见下图)。

I am not using MFC, but if examining the MFC sources would be a good source of information, I am curious to know where in the MFC sources or BCG original sources (I have both) are implemented the Quick Access Toolbar rendering/painting code.

我没有使用 MFC,但如果检查 MFC 源是一个很好的信息来源,我很想知道在 MFC 源或 BCG 原始源(我都有)中的何处实现了快速访问工具栏渲染/绘制代码。

alt text

替代文字

Update: A related neato link from one of the answers below shows the NC (nonclient) Paint message, and how to handle it when painting on a glass frame, and an MSDN article about it here.

更新:来自以下答案之一的相关neato链接显示了NC(非客户端)Paint消息,以及在玻璃框架上绘画时如何处理它,以及有关它的MSDN文章here

回答by David

This is a subset of my "Glass" bookmarks folder, the result of a lotof research / searching on this topic. I've found all of these useful for learning about glass and solving various problems drawing on it. Most of these include Delphi code, but I've noted where it's for another language.

这是我的“玻璃”书签文件夹的一个子集,是对该主题进行大量研究/搜索的结果。我发现所有这些对于学习玻璃和解决各种有关玻璃的问题都很有用。其中大部分包括 Delphi 代码,但我已经注意到它用于另一种语言的位置。

Plain Glass links

普通玻璃链接

  • Using translucent windows with Delphi: good introduction (from the very basics) for using Glass in Delphi forms
  • Custom drawing on glass: covers how to draw a bitmap or other image on a glass area of the window. Covers alpha channels etc too, good overview
  • Using glass in a VC++ project: covers turning glass on, drawing text, handling notifications etc - a good general introduction to how it works. A lot of the underlying details are handled by the VCL (eg the GlassFrame propertyand TForm internals look after a lot of this) but it's very useful to understand the basics of how it's implemented at an API level anyway
  • How to draw on the non-client area: this shows how to draw something like Office's toolbar in the title bar. .Net code, but translatable
  • Setting up a custom title bar: very detailed article about non-client-area drawing (in Delphi, so Delphi code). Followed up by part 2, which demonstrates completely taking over the entire window and mimicking the standard title bar yourself. These two articles will let you mimic Office and Chromeas you requested in the question
  • How to set up various VCL controls to work best on a glass area: the VCL does not support glass very well. You'll often get artifacts, or controls simply not drawing properly at all, no matter what you do to try and solve it. This article lists the basic VCL visual components (labels, buttons, progress bars, etc) and what to set up for each so they draw perfectly, or at least 'as well as possible' when they're placed on a glass area
  • 在 Delphi 中使用半透明窗口:在 Delphi 形式中使用 Glass 的良好介绍(从非常基础开始)
  • 在玻璃上自定义绘图:介绍如何在窗口的玻璃区域上绘制位图或其他图像。也涵盖了 alpha 通道等,很好的概述
  • 在 VC++ 项目中使用玻璃:涵盖打开玻璃、绘制文本、处理通知等 - 对其工作原理的很好的一般介绍。许多底层细节由 VCL 处理(例如,GlassFrame 属性和 TForm 内部处理了很多这些),但无论如何了解它如何在 API 级别实现的基础知识非常有用
  • 如何在非客户区绘制:这显示了如何在标题栏中绘制类似 Office 工具栏的内容。.Net 代码,但可翻译
  • 设置自定义标题栏:关于非客户区绘图的非常详细的文章(在Delphi中,因此是Delphi代码)。接下来是第 2 部分,它演示了完全接管整个窗口并自己模仿标准标题栏。 这两篇文章将让您按照问题中的要求模拟 Office 和 Chrome
  • 如何设置各种 VCL 控件以在玻璃区域上发挥最佳效果:VCL 不能很好地支持玻璃。无论您尝试解决什么问题,您都会经常遇到伪影,或者控件根本无法正确绘制。本文列出了基本的 VCL 可视化组件(标签、按钮、进度条等)以及为每个组件设置的内容,以便在将它们放置在玻璃区域时完美绘制,或者至少“尽可能好”

Advanced, or tangentially related:

高级的或相关的:

回答by Uli Gerhardt

Thesepostson drawing a custom title bar under Vista/Windows 7 might interest you.

这些关于在 Vista/Windows 7 下绘制自定义标题栏的帖子可能会让您感兴趣。

Sample image:

示例图像:

Sample

样本

回答by Philip Rieck

I'm sure you've found the MSDN page about the DWM. It has jumps many topics and a few examples. Some of the "overview" articles there have examples (like the DWM Blur Behind Overview).

我确定您已经找到了有关 DWMMSDN 页面。它有很多主题和几个例子。那里的一些“概述”文章有示例(如概述背后DWM 模糊)。

Unfortunately, other than the documentation, there are precious few good articles. You can start with Using glass on codeproject, and take a look at a detecting glass in delphi- after that using the functions straight from the docs is not too bad. Luckily they are all pretty straight-forward in practice.

不幸的是,除了文档之外,很少有好文章。您可以从在 codeproject使用 glass开始,然后在 delphi 中查看检测 glass- 之后直接使用文档中的功能还不错。幸运的是,它们在实践中都非常直接。

回答by Warren P

Good web site for glass components, including a Glass button:

玻璃组件的好网站,包括玻璃按钮:

http://rmklever.com/

http://rmklever.com/