Visual Styles in Win32 API C GCC MinGW

Our site remains ad-free thanks to our affiliates. This post's featured affiliate is NordVPN. Online VPN service that encrypts your internet traffic and hides your IP with physical location. Upgrade your privacy and security now.

The post is not sponsored by the above affiliate and the content here is not representative of their company.

If you are starting with GUI (Graphical User Interface) programming you may be having some issues with the styles not appear how they are “suppose to”. Buttons may look very old using the “3D Style” and not using the glowing gradient pulsing buttons we are so use to in modern Operating Systems such as Vista, Windows 7 and 8. Below I will explain how to get the Visual Styles enabled in C programming in the Win32 API. I had a lot of issues getting it working so hopefully this will help you out.

First we create a Resource File. This allows us to embed resources into our C program such as Icons, Bitmaps and the Manifest file to enable the Visual Styles. Create a file called resources.rc.

1 24 "Application.manifest"

The value “1” identifies as the type of application. Since this is for a program (EXE) and not a DLL or library we use 1. Sadly I cannot find the documentation for this, but in the future if I do I will be sure to include it here.

The value “24” is the type of resource, and in this case RT_MANIFEST. I set them as the numeric value since I had issues defining them to their “names”. MSDN Resource Types

The value “Application.manifest” is the file we want to embed into the program. The next thign we do is create the Application.manifest file.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
	<assemblyIdentity version="" processorArchitecture="*" name="CompanyName.ProductName.YourApplication" type="win32" />
	<description>Your application description here.</description>
			<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />

There is a lot here, but if you do copy and paste this you will be good if the windows version is at least Windows 7. This just tells the program and windows libraries that your program is indeed a recent program that can use Windows 7 visual styles and newer. MSDN Manifest Files

Now we can “compile” the resource file to be used soon in our program. Run the following command from the directory you have your resources.rc file and Application.manifest file.

$ windres resources.rc -o resources.o

Next we have to add some code to our main application, in this case main.c.

#define _WIN32_WINNT 0x0600
#define _WIN32_IE 0x0900
#include <windows.h>
#include <commctrl.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmd) {
	icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
	/* Your Create Window code and other stuff */

The issue a lot of tutorials skip on is as follows.

#define _WIN32_IE 0x0900

The InitCommonControlsEx require to have at least a value of 0x0300 and that doesn’t get set by default. So you will have to set that, I set mine to 0x0900 since that is the version I am running.

Now we compile the code while linking the libraries.

$ gcc -o program.exe main.c resources.o -lcomctl32 -mwindows

And we are done. You should have nice buttons now, along with other windows.

Related Posts

C Get MP4 Duration

Function to get the duration of a MP4 file using C along with the MP4 container specification.

PHP - Check if Production or Sandbox

Use PHP to check of your site is on your development server or uploaded to the production server.

Windows API Single Key Hotkeys

Learn how to create a program that registers a single key as a hotkey using the Windows API.

Setup PHP Development Web Server Quickly inside of Windows

Quickly setup a PHP development enviornment by using the built in PHP web server with no additional software required.