标题栏中的选项卡:秘密是什么?

发布于 2024-10-30 12:45:53 字数 383 浏览 1 评论 0原文

Chrome 和 Firefox 4 以及其他应用程序现在将一些用户界面放在标题栏中。在 Windows 中,操作系统通常控制整个标题栏。应用程序可以通过删除操作系统标题栏并绘制“假”标题栏(如 WinAmp)来创建自定义标题栏,但只有操作系统知道如何绘制标题栏的非自定义元素(例如关闭/最小化) /Maximize),这因操作系统版本而异。

Chrome 和 Firefox 等应用程序通过什么机制与操作系统“共享”标题栏(在标题栏中放置自定义元素,同时保留原始操作系统视觉主题)?

在此处输入图像描述

在 Chrome 中,选项卡侵占了标题栏,因此没有足够的空间放置标题文本。

Chrome and Firefox 4, among other applications, now put some of their user interface in the title bar. In Windows, the OS normally controls the entire title bar. An application can create a custom title bar by removing the OS title bar and drawing a "fake" title bar instead (like WinAmp), but only the OS knows how to draw the non-customized elements of the title bar (e.g. Close/Minimize/Maximize), which vary by OS version.

By what mechanism do apps like Chrome and Firefox "share" the title bar with the OS (put custom elements in the title bar while keeping the original OS visual theme)?

enter image description here

In Chrome, the tabs encroach upon the title bar so that there is not enough space for title text.

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

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

发布评论

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

评论(4

季末如歌 2024-11-06 12:45:53

Microsoft has a very detailed explanation in the article Custom Window Frame Using DWM.

白况 2024-11-06 12:45:53

标题栏和窗口边框属于窗口的非客户区 (NC)。如果您正在编写基于消息泵的应用程序,您可以使用 WM_NCPAINT 和 WM_NCHITTEST 窗口消息提供您自己的逻辑和该区域的外观(就像 Jon 所写的那样)。

虽然该区域在以前的 Windows 版本中使用得相当少,但 Microsoft 最近(至少自 Vista 以来)开始使非客户端区域更具吸引力且功能更丰富。

在现代应用程序中,完全忽略非客户区并创建一个没有严格窗口边框并因此仅包含客户区的窗口是很常见的。使用此方法,窗口必须提供自己的实现来绘制窗口标题和窗口按钮(最小化、最大化/恢复和关闭)。将此技术与窗口透明度相结合,可以轻松创建令人兴奋的用户界面。

如果您使用 WPF,您会发现 WindowChrome 类非常有用为此目的。此类是 .NET 4 框架的一部分,可作为 .NET 3.5 的单独的库使用。

编辑

显然有人不喜欢这个答案。需要澄清的是:我并不是说 Chrome 或任何其他应用程序就是这样做的。我的意思是,我所描述的这是一个可行的解决方案,我自己和我工作的公司已在多个项目中使用过该解决方案,并且我知道其他几个应用程序也使用相同的方法。它可能不是最好的,但它肯定是一种方法! :-)

The title bar and the window border belongs to the non-client area (NC) of the window. If you're writing a message pump based application you can provide your own logic and appearance of this area using the WM_NCPAINT and WM_NCHITTEST window messages (just like Jon wrote).

While this area has been quite moderately used in previous Windows versions, Microsoft has recently (at least since Vista) started to make the non-client area more attractive and feature rich.

In modern applications it is quite common to completely ignore the non-client area and instead create a window that does not have a strict window border and thus consists of ONLY a client area. With this method the window must provide it's own implementation for drawing the window title and window buttons (minimize, maximize/resore and close). Combining this technique with window transparency makes it possible and quite easy to create exciting user interfaces.

If you are using WPF you'll find the WindowChrome class very useful for this purpose. This class is part of the .NET 4 framework and available as a separate library for .NET 3.5.

Edit

Obviously someone does not like this answer. Just to be clear: I'm not saying that this is how Chrome or any other application is doing it. I am saying that how I've described it is a feasible solution which myself and the company I work for has used in several projects and I know for a fact that several other applications use the same approach. It might not be the best, but it is certainly a way to go about it! :-)

來不及說愛妳 2024-11-06 12:45:53

我懒得去查看 chrome 和 firefox 的源代码来找出它们到底做了什么,但它很可能包括对 WM_NCPAINT 和 WM_NCHITTEST 的自定义处理。他们可以允许操作系统进行基本的标题栏绘制,然后将自己的部分粘贴在顶部。另一种方法是自己完成所有绘制工作,包括调用 DWM api 来处理所有花哨的部分。不管怎样,尝试去做都是一件丑陋的事情,如果你做得不好,它看起来和感觉起来都会很糟糕。

I'm too lazy to go looking at chrome and firefox's source to find out exactly what they did, but it most likely includes custom handling for WM_NCPAINT and WM_NCHITTEST. They can allow the OS to do the basic titlebar painting, then stick their own bits on top. The alternative is to do all the painting themselves, including calls to the DWM api to handle all the fancy bits. Either way, it's an ugly thing to try and do, and if you don't do it just right, it'll look and feel terrible.

森林散布 2024-11-06 12:45:53

也许这也值得一看:
https://github.com/lstratman/.NETTitleBarTabs

和另一个链接:
http://www.nuget.org/packages/TitleBarTabs/

我自己没有尝试过,并将对其进行研究以了解其工作原理和效果如何。

Perhaps this is worth to look at as well:
https://github.com/lstratman/.NETTitleBarTabs

and another link:
http://www.nuget.org/packages/TitleBarTabs/

I have not tried it myself, and will look into it to see how and how well it works.

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