In this article, I will give you some source code to create per pixel alpha blending windows.
First, some images:
Nice, isn't it?
For creating a per-pixel window, we are going to use:
- One 24bit Bitmap with alpha channel
- The GDI function,
24bit Bitmap with Alpha Channel
The most tricky part of creating the bitmap is finding a simple file format that has an embedded alpha channel.
The selected file format for the first incarnation of this article was PSP (Paint Shop Pro™ from Jasc®), but now the recommended file format has been changed to PNG (Portable Network Graphics).
For loading PNG files, I use the paintlib library. This library can also load files from PCX, TGA and TIFF formats.
This demo application does not use
paintlib directly; instead it uses a
paintlib wrapper DLL, ImgDecoder.Dll.
For loading PSP files, I've created a function called
To use this function, we must have a top-level window (in this sample, this is implemented by the class
CDummyDialog) with the extended style
Before we can pass the bitmap to the
UpdateLayeredWindow function, we must pre-multiply the rgb channels with the alpha channel. For this, you just have to call the
PreMultiplyRGBChannels function (take a look at
From here on, read the source code in
Installing & Building
- Make sure you have the SDK for Windows® NT 5.0.
- Download and extract the source code of this article.
- Build and enjoy!
If you want to build the ImgDecoder.Dll, you also have to:
- Download paintlib and all the required libraries
- Download the ImgDecoder project
- Extract the
ImgDecoder project to the
- Build the
- Copy the resulting ImgDecoder.dll and ImgDecoder.lib to the bin directory of this article's demo application.
- You must mention my name in your application documentation/help box.
- I would appreciate it if you message me on the article forum letting me know that you are using this code.
- I cannot be held responsible for any kind of data loss caused directly or indirectly by the use of this code - use it at your own risk.
- You cannot sell this code - this is free software.
Don't forget if you have any constructive thoughts, please leave a comment below!
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.