Click here to Skip to main content
15,889,863 members
Articles / Desktop Programming / MFC

Using the AlphaBlend Function

Rate me:
Please Sign up or sign in to vote.
4.43/5 (19 votes)
1 Feb 2000 341.3K   7.4K   49   67
A sample application that uses the AlphaBlend function to produce a transparent splash screen

Sample Image - alphablend.gif

Note: The code in this article is restricted to win98 and win2000.

Do you want a cool splash window? Do you think the general splash window is not good enough for your app? Then this sample source is for you.

My semi-transparent splash window uses the AlphaBlend function. When I found this function, I was so surprised! The function works just like BitBlt for bitmaps that have transparent or semitransparent pixels. Here is the AlphaBlend function's syntax.

C++
BOOL AlphaBlend( HDC hdcDest,
  int nXOriginDest,
  int nYOriginDest,
  int nWidthDest,
  int nHeightDest,
  HDC hdcSrc,
  int nXOriginSrc,
  int nYOriginSrc,
  int nWidthSrc,
  int nHeightSrc,
  BLENDFUNCTION blendFunction
);

The important parameter is the last one, BLENDFUNCTION.

C++
typedef struct _BLENDFUNCTION {
    BYTE     BlendOp;
    BYTE     BlendFlags;
    BYTE     SourceConstantAlpha;
    BYTE     AlphaFormat;
}BLENDFUNCTION;
  • BlendOp must be AC_SRC_OVER
  • BlendFlags must be 0
  • SourceConstantAlpha must be between 0 (transparent) and 255 (semi-transparent)
  • AlphaFormat must be AC_SRC_ALPHA

MSDN states: The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparency value to be used on the entire source bitmap. The SourceConstantAlpha value is combined with any per-pixel alpha values. If you set SourceConstantAlpha to 0, it is assumed that your image is transparent. Set the SourceConstantAlpha value to 255 (indicates that the image is opaque) when you only want to use per-pixel alpha values.

See the sample application for a demonstration.

Just enjoy!!

Ajou University C.C. 4th member.

License

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.


Written By
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at wooseok.seo@gmail.com

Comments and Discussions

 
QuestionCode not using MFC? Pin
Jon Boyce31-Aug-00 0:05
Jon Boyce31-Aug-00 0:05 
GeneralWorks on WinNT 4.0 Pin
Torsten17-Jul-00 3:12
Torsten17-Jul-00 3:12 
GeneralProblem with GDI32 Pin
sebastien16-May-00 0:07
sebastien16-May-00 0:07 
GeneralRe: Problem with GDI32 Pin
Smile Seo4-Jul-00 8:13
sussSmile Seo4-Jul-00 8:13 
GeneralAnswer: How to run it in any Windows. Pin
Yury Goltsman28-Mar-00 2:40
Yury Goltsman28-Mar-00 2:40 
GeneralRe: Answer: How to run it in any Windows. Pin
Error Coad11-Jul-00 7:03
sussError Coad11-Jul-00 7:03 
GeneralRe: Answer: How to run it in any Windows. Pin
Yury Goltsman11-Jul-00 22:00
Yury Goltsman11-Jul-00 22:00 
GeneralHere's another possibility Pin
21-Jul-01 5:00
suss21-Jul-01 5:00 
Not having Windows 95 (I've got Millenium; which, by the way, it works fine on, as one would expect--but then again, we're talking about Microsoft here, and they don't always make much sense), I would have no way of checking this, but has anybody checked to see if there is a service pack upgrade or something that will upgrade the version of Wingdi.dll to a version that includes the AlphaBlend function?
GeneralRe: Here's another possibility Pin
Henry P.3-Mar-03 6:03
Henry P.3-Mar-03 6:03 
GeneralWin95 Pin
Alex Butler17-Mar-00 9:14
Alex Butler17-Mar-00 9:14 
GeneralRe: Win95 Pin
21-Jul-01 4:57
suss21-Jul-01 4:57 
QuestionDoes that mean a project w/ this code in it cannot run under 95/NT ? Pin
Christian4-Mar-00 3:02
Christian4-Mar-00 3:02 
AnswerIt might, it depends... Pin
21-Jul-01 4:53
suss21-Jul-01 4:53 
GeneralRe: It might, it depends... Pin
26-Oct-01 0:14
suss26-Oct-01 0:14 
GeneralThat's noted!! Pin
Smile Seo12-Feb-00 23:42
sussSmile Seo12-Feb-00 23:42 
GeneralRe: That's noted!! Pin
Keith Rule13-Feb-00 10:27
professionalKeith Rule13-Feb-00 10:27 
GeneralThis Technique only works on Win98 & Win2k Pin
Keith Rule11-Feb-00 7:37
professionalKeith Rule11-Feb-00 7:37 
GeneralRe: This Technique only works on Win98 & Win2k Pin
15-Jun-01 16:22
suss15-Jun-01 16:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.