I’ve always been fascinated by classic Win32 applications. They start up really quick, are always really fast and they rarely hog resources. The speed and fast startup is a huge plus for me, especially compared to “modern” desktop applications built with .NET.
I’m going to try and make a simple Win32 app, a program which helps me store the Spotlight lock-screen images that are changed periodically.
The Compiler
The first step is getting the tools we need. I don’t feel like installing the massive Visual Studio IDE for this project so I’ll go with mingw-w64 which is a free port of the GNU C/C++ Compiler and other libraries/tools for 64 bit Windows. To install this, I’ll use a package distribution program called WinBuilds.
All packages from WinBuilds total are around 500MB in size (unextracted), compared to the multiple gigabytes for Visual Studio.
The WinBuilds directory will contain a “bin” subdirectory, containing EXE files for all the tools. Ideally one should add this directory to the PATH environment variable, but I’m going to be using a batch script to manually set for a terminal session.
add-mingw-to-path.bat
set PATH=%PATH%;c:\winbuilds\bin\
where C:\winbuilds\bin
is your WinBuilds install directory.
I’ll be using VSCode as my text editor for this series. First I’ll make a simple C++ program that prints “Hello” and compile it with g++. Then I run the output EXE file. Seems to work so far.
Mingw-w64’s g++
produces Windows PE (portable executable) .EXE files, which is neat. I’ve not used any Windows APIs here, so hello.exe is not really a proper Win32 application yet.
To use the Windows API, we need to include windows.h
and use Windows API functions. To test my setup I’ll use the first program from theForger’s Win32 API Programming Tutorial, the most famous Win32 API programming tutorial.
It works. I’ll add more stuff to it in the next part.