WinAPI: Create resizable window without title bar, but with minimize/maximize/close buttons (as Firefox/Chrome/Opera)

后端 未结 3 1934
迷失自我
迷失自我 2020-12-13 00:56

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 resiza
相关标签:
3条回答
  • 2020-12-13 01:25

    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):

    • Setting up a custom title bar on Windows Vista / 7
    • Setting up a custom title bar - reprise This one has a demo app showing the result of a number of variations / options.

    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 :)

    0 讨论(0)
  • 2020-12-13 01:26

    I believe they create a normal window and then paint over the title bar with their custom widgets/tabs. This is evident in Firefox, as when it hangs you can see the normal Windows title bar appear over the tabs.

    0 讨论(0)
  • 2020-12-13 01:28

    You can create a window with or without caption - whatever is more appropriate from the point of view of desired customization (that is "without" is you want to do it "without title bar" as you say), and the important wart is that you take over painting non-client area - this is the key thing.

    At this point, there is no one to paint your mimimize/maximize buttons already. It does not however mean that you have to do the painting right from scratch and mimic standard UI. There is DrawFrameControl and friends API where you can use DFCS_CAPTIONMIN argument and have minimize button painted for you. You will also want to respond to other non-client area messages, e.g. handle WM_NCHITTEST to tell Windows where your new window buttons are.

    You might also want to check Visual Styles Reference to leverage theme-enabled drawing API such as DrawThemeBackground.

    A simple example of this activity is putting an additional button onto caption, such as described in detail here: CCaptionButton (buttons for the titlebar).

    0 讨论(0)
提交回复
热议问题