Click here to Skip to main content
Licence 
First Posted 1 Feb 2000
Views 208,763
Bookmarked 40 times

Using the AlphaBlend function

By | 1 Feb 2000 | Article
A sample application that uses the AlphaBlend function to produce a transparent splash screen
  • Download source files - 35 Kb
  • Sample Image - alphablend.gif

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

    Do you want to 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

    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 last one, BLENDFUNCTION.

    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
    MSND states:  The SourceConstantaAlpha member of BLENDFUNCTION specifies an alpha transparancy 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

    About the Author

    Wooseok Seo

    Software Developer (Senior)

    Korea (Republic Of) Korea (Republic Of)

    Member

    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

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board. (secure sign-in)
     
    Search this forum  
     FAQ
        Noise  Layout  Per page   
      Refresh
    GeneralMy vote of 3 PingroupMahdi Nejadsahebi21:24 30 Apr '11  
    GeneralMy vote of 2 PinmemberMember 3186840:41 6 Jan '10  
    QuestionAlphaBlend draws over the existing backgruound making it darker. gradually losing transaprency PinmemberVC++Maniac21:15 20 Apr '09  
    GeneralAbout OnPaint with the AlphaBlend(); [modified] PinmemberTed Lin22:12 16 Aug '07  
    Dear Sir,
     
    I modify your sample code to let the form can be moved.
    I set the fix value like "SourceConstantAlpha = 185";
    And set the bitmap with all dark.
    I run the sample, the graphic is always dark.
     
    I think the CClientDC is not release completed, and the next paint is coming.
    I research the CClientDC, the document said it will destory automatically.
    But the program run is wrong.
     
    Do you have any idea to fix this problem?Smile | :)
    Thanks.
     

     
    -- modified at 4:20 Friday 17th August, 2007
    GeneralAlphaBlend wrong formula ?! PinmemberOctopod10:17 23 Sep '06  
    GeneralRe: AlphaBlend wrong formula ?! PinmemberOctopod10:50 23 Sep '06  
    GeneralThank you PinmemberNick Z.10:41 23 May '05  
    GeneralProblem with AlphaBlend Pinmemberacidutzu23:13 23 Mar '05  
    GeneralRe: Problem with AlphaBlend Pinmemberjgarnett15:59 27 Oct '05  
    GeneralQuestion Pinmemberone_eddie11:40 1 Oct '04  
    GeneralGreat stuff! PinmemberJustDan17:36 24 Jan '04  
    GeneralRe: Great stuff! Pinmemberanothermxw19:08 4 Apr '04  
    GeneralRe: Great stuff! PinsussAnonymous14:18 5 Apr '04  
    GeneralNo with Dialog Pinmembermojster5:42 17 May '03  
    GeneralAlgorithm Code PinmemberJack Rabbit17:34 27 Feb '03  
    GeneralRe: Algorithm Code PinmemberHenry P.17:57 27 Feb '03  
    GeneralRe: Algorithm Code PinmemberJack Rabbit19:38 28 Feb '03  
    GeneralRe: Algorithm Code PinsussAnonymous6:27 3 Mar '03  
    GeneralRe: Algorithm Code PinmemberJack Rabbit4:50 8 Mar '03  
    GeneralRe: Algorithm Code PinmemberHenry P.19:22 31 Mar '03  
    GeneralRe: Algorithm Code PinmemberB2kguga10:04 25 Feb '07  
    GeneralWin95/98/ME vs. WinNT/2000/XP PinmemberHenry P.16:57 27 Feb '03  
    GeneralRe: Win95/98/ME vs. WinNT/2000/XP PinmemberChristian Graus17:57 27 Feb '03  
    GeneralRe: Win95/98/ME vs. WinNT/2000/XP PinmemberHenry P.9:21 3 Mar '03  
    GeneralRe: Win95/98/ME vs. WinNT/2000/XP PinmemberChristian Graus9:29 3 Mar '03  

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

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

    Permalink | Advertise | Privacy | Mobile
    Web01 | 2.5.120529.1 | Last Updated 2 Feb 2000
    Article Copyright 2000 by Wooseok Seo
    Everything else Copyright © CodeProject, 1999-2012
    Terms of Use
    Layout: fixed | fluid