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

15,960

Solution 1

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

Solution 2

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

Share:
15,960
Nubok
Author by

Nubok

Mathematician (Diplom-Mathematiker) and Computer Scientist (BSc). Doing doctorate in mathematical optimization. For any recruiters who want to contact me: I will not react to job offers that contain no salary information. Not just for pecuniary reasons, but also because this information sends a strong signal on what skill level you expect for the job. Also if you send an (interesting) job offer, it is strong waste of time for me if the job advertisement does not make it very clear what the job is actually exactly about. I have written an article (in German) on my website: https://www.lambda-v.com/opinionated/stellenanzeige_gehalt.html Sorry to be so upfront, but respecting this, saves you and me a lot of precious time and saves both sides from disappointments.

Updated on June 03, 2022

Comments

  • Nubok
    Nubok almost 2 years

    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?

  • David Heffernan
    David Heffernan over 12 years
    Hmm, I really don't think this is true.
  • David Heffernan
    David Heffernan over 12 years
    Theme API is the way to do this but it's easy to say that and darned hard to put it all together.
  • Roman R.
    Roman R. over 12 years
    True. As long as you don't have it painted for you any longer, you have to put quite some effort into making it look consistent with standard UI.
  • Dominik Grabiec
    Dominik Grabiec over 12 years
    Normal, owner drawn windowm uses custom drawing to paint over the normal title bar. If in doubt, check out the source code, it is open source after all.
  • Nubok
    Nubok over 12 years
    Very helpful. I believe, you and Roman R. both would have earned the "Answered" flag. Unluckily I can give it only to one of you. :-(