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 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 KbDownload source - 2 Kb

Comments
test
Posted by Legacy on 12/13/2002 12:00amOriginally posted by: test
test
Replytest
Read this if you are having problems
Posted by Legacy on 08/28/2002 12:00amOriginally posted by: jase jennings
If you just download the source files, you will have problems with "AlphaBlending.h", because this file is not part of the zip.
If you download the tes application, you get all the files.
And don't forget to include the #define in stdafx.h (it says use 0x0500, but of you are using windows xp then use 0x0501 instead)
Replyworks with some modifications
Posted by Legacy on 04/10/2002 12:00amOriginally posted by: g.sharp
i had to comment out the line as follows:
// #include "AlphaBlending.h"
in AlphaBlend.C
when using:
Visual C++ 6
Windows XP
November 2001 Platform SDK
(In an MFC Application)
May just be me but i thought i would throw it up here
in case anyone else ran into problems.
ReplyOpacity is possible anywhere
Posted by Legacy on 12/14/2001 12:00amOriginally posted by: Amit Gefen
ReplyIs alpha blend exist on WD98 ???
Posted by Legacy on 11/14/2001 12:00amOriginally posted by: DJEEN
Is another way exist to create an transparent window for WD98 for exemple ... ???
ReplyTransparency/Alpha vs. Windows Media Player
Posted by Legacy on 05/21/2001 12:00amOriginally posted by: Mac
I'm trying to build a translucent window that overlays a Windows Media Player window so that the playing video shows through the overlaying window. The overlaying window should be about half translucent, not completely transparent.
I've experimented with Mike Ryan's alpha blend approach (thanks for the example!). I've also tried using the SetLayeredWindowAttributes method following Bernhard Hammer's example at http://www.codeproject.com/useritems/trans.asp.
The results are similar. With both approaches, the translucent effect works great on top of most other windows, except when I put it on top of WMP playing a video. In this case, the rectangle where the video is playing (not the whole WMP) turns gray in the overlaying window, and the video is not visible.
So, does anyone know how to make a translucent window that overlays WMP and properly shows WMP's playing video through the overlaying window? Is there something special I need to do in my use of WMP? I'm using WMP as an Active X control in my MFC Visual C++ application.
ReplyAlpha Blending and ActiveX Controls
Posted by Legacy on 04/17/2001 12:00amOriginally posted by: Eric Levy
Can ActiveX control backgrounds make use of the alpha blending features in Win2000. I am trying to create an ActiveX control with a transparent background and text changing every second, which can be placed on a dynamic, background. I want to try and place this control in a Power Point Presentation. Will this method work, or do you have any ideas?
ReplyThanks,
Eric Levy
Which SDK you mean?
Posted by Legacy on 04/14/2001 12:00amOriginally posted by: Ismail PAZARBASI
Hi,
I am using Windows 2000 Advanced Server. I visited the SDK Downloads page, but I think I couldn't find that SDK.
Do you please send which SDK you mean? There is not a title about "Windows 2000 API" or any similar SDK.
Thank you for your interest,
ReplyBest regards.