Tree branch
Another tree branch
OpenGL Tutorials
Spider web
Facebook Twitter Google Plus
Changing a Window's style (Win32API) with CreateWindowEx

This tutorial is going to be short but it's surely handy. I've been asked these questions at least five times: "How do I make my window non-resizable?" and "How do I remove the minimize and/or maximize buttons from the title bar menu?". Luckily, all of this(and more) can be done during process of creating the window with the function CreaetWindowEx.

As you've observed in the previous tutorials the fourth parameter of the function takes window style flags. By OR'ing various flags you can achieve the desired style. In previous tutorials only one flag was used and it was WS_OVERLAPPEDWINDOW. This one long flag is actually a collection of flags OR'ed(using the bitwise OR operator) together and not just one style.

WS_OVERLAPPEDWINDOW contains all of the following styles in one:

  • WS_OVERLAPPED
  • WS_CAPTION
  • WS_SYSMENU
  • WS_THICKFRAME
  • WS_MINIMIZEBOX
  • WS_MAXIMIZEBOX
  • As you saw in previous tutorials this creates a general-looking window with a title bar which shows the name of the window and the three "system" buttons - minimize, maximize and close. I'll quickly go over the styles by introducing you to this image below and then explain what style does what.

    Window create properties are WS_OVERLAPPED, WS_MINIMIZEBOX, WS_MAXIMIZEBOX, WS_SYSMENU, WS_BORDER and WS_THICKFRAME.

    WS_OVERLAPPED creates a window with a title bar. The three flags located in the upper right corner of the image indicate which system buttons will appear. If in any case you don't want the user to see(and use) the minimize and maximize buttons only specify the WS_SYSMENU style.

    WS_BORDER adds a border to your window. To make this border "thick" (there are two kinds of borders - normal and thick) add WS_THICKFRAME style; a thick frame I believe is 2 more pixels thicker.

    This is some really straightforward stuff. For example if you wanted to create a window that only has a close button and will not be resizable and have a normal border thickness, you would pass the following flags to the CreateWindowEx function:

    // Create the window hwnd = CreateWindowEx(NULL, WNDCLASSNAME, "Window", WS_OVERLAPPED|WS_BORDER|WS_SYSMENU, 0, 0, 300, 300, NULL, NULL, hinstance, NULL);

    Note there is no source code for this tutorial because it's too simple.

    © 2014 OpenGL Tutorials.

    About | Privacy | Contact

    Built with Tornado PHP FrameworkTornado PHP Framework with Wooden PHP Template template | Web design by Web Design by Greg.