Click here to Skip to main content
15,889,595 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

 
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 
Though the article doesn't mention it, this technique is limited to Win98 & Win2k. Don't expected it to work on WinNT 4.0 or Win95
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.