Alpha Blending (Transparent) Windows | CodeGuru

Alpha Blending (Transparent) Windows

Environment: Windows 2000 VC 6.0 Newest Win32 API (Required) IMPORTANT NOTE: To compile this sample you must be running Windows 2000 and the latest WIN32 API which you can download from Microsoft. This program will only run under Windows 2000. It makes use of the new features of the OS. The purpose of this example […]

Written By
CodeGuru Staff
CodeGuru Staff
Jul 30, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: Windows 2000 VC 6.0 Newest Win32 API (Required)

IMPORTANT NOTE:

To compile this sample you must be running Windows 2000 and the latest WIN32 API which you can download from
Microsoft.
This program will only run under Windows 2000. It makes use of the new features of the OS.

The purpose of this example is to enable the new Alpha Blending features of Microsoft Windows 2000. It is very easy to do and hardly
needs a whole class to do it, but I felt a little cheesy just posting two function calls. 🙂

To use, add the CAlphaBlend class to your project. Modify the StdAfx.h file to contain the following lines right above the
#define VC_EXTRALEAN:

#define _WIN32_WINNT 0x0500
#define WINVER 0x0500

These lines will tell the compiler that it is for Windows NT 5.0 (better known as Windows 2000). They are critical and only work
if you have the newest Win32 API.

Then add the following lines of code before you display your window (or after you display it):

// assuming we are about to ShowWindow() in the MyApp.cpp of an SDI
CAlphaBlend ab(m_pMainWnd);
ab.SetTransparent();

This code can be called before or after a window is displayed. You can adjust the opacity (amount of transparency) with the constructor,
or the following function:

// valid ranges are 0-255, 255-being totally opaque (not transparent)
ab.SetOpacity(125);

// I found 220 does about the best blend.

One final note. The alpha blending in Windows 2000 is very slow. I have tried many different ways to optimize it and could never
get it any faster than it is. The only way I can think of is to handle the algorithm and thus the Alpha Blending myself. I don’t really
want to tackle that at the moment, so any optimizations any of you could make would be cool. Please let me know.

Downloads


Download demo project – 18 Kb


Download source – 2 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.