Click to choose your tutorial
Tutorial 1: SDK
Tutorial 2: Creating a Window
Tutorial 3: Vulkan Instance
Tutorial 4: Supported Extensions
Tutorial 5: Drawing Points
Tutorial 6: Drawing Lines
Tutorial 7: Drawing Triangles
Tutorial 8: Introduction to Shaders
Tutorial 9: Loading Shaders
Tutorial 10: Using Multiple Shaders
Tutorial 11: Loading 3D Model
Tutorial 12: Displaying 3D Model
Tutorial 13: Vertex Animation
Tutorial 14: Bone Animation
OpenGL Tutorials
site is v0.1a build Sep 11, 2016
Join to be notified of new tutorials

Win32 API Tutorial 5 - Changing a Window's style (Win32API) with CreateWindowEx

Written by staff. Contact us to submit your article for review.
Sep 13, 2016
tags Tags changing, window, style
Post #40

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:

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


    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.

    article tab
    Follow OpenGL Tutorials
    You will only receive important news about OpenGL tutorial updates.
    Who is joining?
    • Programmers You want to stay in touch to receive OpenGL tutorial updates.
    • Game Devs You're a game developer, and you also want to learn more about OpenGL!
    • Supporters You have invested interest in supporting OpenGL tutorial site.
    Follow OpenGL Tutorials