Be Friendly
Search This Site for Tutorials About...

How to Change a Window's Style? (C++ Programming)

Just for fun: How to Make French Toast

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 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, and 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.

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.

Did this article help you learn something new?

I enjoy writing for the Internet audiences because my thoughts are instantly published to the entire world. My work consists of writing educational articles about making websites to help people learn. If you enjoyed reading this article, or learned something new, then I have succeeded.

If the content on this website somehow helped you to learn something new, please let others know about it by sharing it on your website or on your Facebook page with your friends. In addition you can help by making a donation or bookmarking this site.