windows 标题栏中的标签:有什么秘密?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5558118/
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
Tabs in title bar: what's the secret?
提问by Qwertie
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.
Chrome 和 Firefox 4 以及其他应用程序现在将它们的一些用户界面放在标题栏中。在 Windows 中,操作系统通常控制整个标题栏。应用程序可以通过删除操作系统标题栏并绘制“假”标题栏来创建自定义标题栏(如 WinAmp),但只有操作系统知道如何绘制标题栏的非自定义元素(例如关闭/最小化/Maximize),因操作系统版本而异。
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)?
Chrome 和 Firefox 等应用程序通过什么机制与操作系统“共享”标题栏(在标题栏中放置自定义元素,同时保留原始操作系统视觉主题)?
In Chrome, the tabs encroach upon the title bar so that there is not enough space for title text.
在 Chrome 中,标签会侵占标题栏,因此标题文本没有足够的空间。
采纳答案by Mark Ransom
Microsoft has a very detailed explanation in the article Custom Window Frame Using DWM.
微软在Custom Window Frame Using DWM一文中有非常详细的解释。
回答by M?rten Wikstr?m
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).
标题栏和窗口边框属于窗口的非客户区 (NC)。如果您正在编写基于消息泵的应用程序,您可以使用 WM_NCPAINT 和 WM_NCHITTEST 窗口消息(就像 Jon 写的那样)提供您自己的逻辑和该区域的外观。
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.
虽然这个区域在以前的 Windows 版本中已经相当温和,但微软最近(至少从 Vista 开始)开始使非客户区更具吸引力和功能丰富。
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 classvery useful for this purpose. This class is part of the .NET 4 framework and available as a separate libraryfor .NET 3.5.
如果您使用 WPF,您会发现WindowChrome 类对此非常有用。此类是 .NET 4 框架的一部分,可作为.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! :-)
显然有人不喜欢这个答案。澄清一下:我并不是说 Chrome 或任何其他应用程序就是这样做的。我是说我如何描述它是一个可行的解决方案,我自己和我工作的公司已经在几个项目中使用过,而且我知道其他几个应用程序使用相同的方法。它可能不是最好的,但它肯定是一种解决方法!:-)
回答by Jon
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.
我懒得去查看 chrome 和 firefox 的源代码来确切地找出它们做了什么,但它很可能包括对 WM_NCPAINT 和 WM_NCHITTEST 的自定义处理。他们可以让操作系统进行基本的标题栏绘制,然后将自己的位贴在上面。另一种方法是自己完成所有绘制,包括调用 DWM api 来处理所有花哨的位。无论哪种方式,尝试去做都是一件丑陋的事情,如果你做得不对,它看起来和感觉都会很糟糕。
回答by RooiWillie
Perhaps this is worth to look at as well: https://github.com/lstratman/.NETTitleBarTabs
也许这也值得一看:https: //github.com/lstratman/.NETTitleBarTabs
and another link: http://www.nuget.org/packages/TitleBarTabs/
和另一个链接: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.
我自己没有尝试过,我会研究它以了解它的工作原理和效果。