WinAPI:创建可调整大小的窗口没有标题栏,但最小化/最大化/关闭按钮(如Firefox / Chrome / Opera) [英] WinAPI: Create resizable window without title bar, but with minimize/maximize/close buttons (as Firefox/Chrome/Opera)

查看:1350
本文介绍了WinAPI:创建可调整大小的窗口没有标题栏,但最小化/最大化/关闭按钮(如Firefox / Chrome / Opera)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您查看Firefox,Chrome或Opera浏览器的窗口,您会注意到他们的窗口




  • 最大化/关闭按钮

  • 可调整大小

  • ,但没有标题栏。



我感兴趣:我如何创建这样的窗口?



我已经尝试过的

我在StackOverflow(和googled,)也环顾四周,发现这个:



不幸的是,这没有帮助完整:



第一步是扩展打开一个没有标题栏与win32的窗口

  hWnd = CreateWindow(szWindowClass,szTitle,WS_BORDER,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);

SetWindowLong(hWnd,GWL_STYLE,WS_SIZEBOX);
//查看http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx上的备注
SetWindowPos(hWnd,0,
0,0, 0,0,//位置+大小
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

当然,这不提供最小化/最大化按钮,但另一方面, /最大化按钮,我必须:

  SetWindowLong(hWnd,GWL_STYLE,WS_SIZEBOX | WS_MAXIMIZEBOX | 
WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION);

为什么这种组合似乎是必要的?首先我可能想要 WS_MAXIMIZEBOX |



http://msdn.microsoft.com/en-us/library/ms632600.aspx 说,如果我设置 WS_MAXIMIZEBOX WS_MINIMIZEBOX ,我也必须设置 WS_SYSMENU 。当我设置 WS_SYSMENU 时,我还必须设置 WS_CAPTION ,但这不是我想要的,避免标题栏(确实:如果未设置 WS_CAPTION ,则不会显示最小化/最大化按钮)。



那么该怎么办?

解决方案

程序删除非客户区(标题栏)处理用于再现窗口按钮,图标,系统菜单等。这样做的好处是,他们可以绘制到新的标题栏,这实际上是标准客户端区域的一部分,添加标签或其他自定义控件。



以下两篇文章将告诉您如何在Vista及以上版本(使用DWM)上执行此操作:





这是非常复杂的事情,得到正确,所以上述两篇文章是非常宝贵的。作者必须把大量的工作投入他们!这两个链接都有用Delphi编写的示例代码,但应该很容易翻译成C ++ - 这些概念是完全相同的,只是语法。



Glass和DWM的一般资源中,因为它都密切相关。您会发现列表中包含的以上两个链接:)


If you look at the windows of the browsers Firefox, Chrome or Opera, you'll notice that their windows

  • have minimize/maximize/close buttons
  • are resizable
  • but have no title bar

I'm interested: how can I create such a window?

What I have already tried

I looked around on StackOverflow (and googled, too), and found this: opening a window that has no title bar with win32

Unluckily, this didn't help completely:

The first step was to extend the solution proposed on opening a window that has no title bar with win32

hWnd = CreateWindow(szWindowClass, szTitle, WS_BORDER, 
  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
  NULL, NULL, hInstance, NULL);

SetWindowLong(hWnd, GWL_STYLE, WS_SIZEBOX);
// See remarks on http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx
SetWindowPos(hWnd, 0, 
   0, 0, 0, 0, // Position + Size
   SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

Of course, this delivers no minimize/maximize buttons, but on the other hand, if I want minimize/maximize buttons, I have to do:

SetWindowLong(hWnd, GWL_STYLE, WS_SIZEBOX | WS_MAXIMIZEBOX | 
    WS_MINIMIZEBOX | WS_SYSMENU | WS_CAPTION);

Why does this combination seem to be necessary? First I probably want WS_MAXIMIZEBOX | WS_MINIMIZEBOX since I want these buttons.

But http://msdn.microsoft.com/en-us/library/ms632600.aspx says that if I set one of WS_MAXIMIZEBOX and WS_MINIMIZEBOX, I also have to set WS_SYSMENU. And when I set WS_SYSMENU, I also have to set WS_CAPTION but this is not what I want, because I wanted to avoid the title bar (indeed: if WS_CAPTION is not set, no minimize/maximize buttons are shown).

So what is to do?

解决方案

The programs remove the non-client area (the title bar) and have a bunch of custom handling for reproducing the window buttons, icons, system menu etc. The benefit of this is that they can draw to the new "title bar", which is actually part of the standard client area, adding tabs or other custom controls.

The following two articles will show you how to do this on Vista and above (using the DWM):

This is very complex to do and get right, so the above two articles are invaluable. The author must have put a lot of work into them! Both links have example code written in Delphi, but it should be easy enough to translate it to C++ - the concepts are identical, it's just syntax.

You might also be interested in general resources on Glass and DWM, since it's all closely related. You'll spot the above two links included in that list :)

这篇关于WinAPI:创建可调整大小的窗口没有标题栏,但最小化/最大化/关闭按钮(如Firefox / Chrome / Opera)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆