Click here to Skip to main content
Click here to Skip to main content

Using the AlphaBlend function

By , 1 Feb 2000
 
  • Download source files - 35 Kb
  • Sample Image - alphablend.gif

    <!-- Article Starts --> 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)
    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

     
    Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralMy vote of 3groupMahdi Nejadsahebi30-Apr-11 21:24 
    GeneralMy vote of 2memberMember 3186846-Jan-10 0:41 
    QuestionAlphaBlend draws over the existing backgruound making it darker. gradually losing transaprencymemberVC++Maniac20-Apr-09 21:15 
    GeneralAbout OnPaint with the AlphaBlend(); [modified]memberTed Lin16-Aug-07 22:12 
    GeneralAlphaBlend wrong formula ?!memberOctopod23-Sep-06 10:17 
    GeneralRe: AlphaBlend wrong formula ?!memberOctopod23-Sep-06 10:50 
    GeneralThank youmemberNick Z.23-May-05 10:41 
    GeneralProblem with AlphaBlendmemberacidutzu23-Mar-05 23:13 
    GeneralRe: Problem with AlphaBlendmemberjgarnett27-Oct-05 15:59 
    GeneralQuestionmemberone_eddie1-Oct-04 11:40 
    GeneralGreat stuff!memberJustDan24-Jan-04 17:36 
    GeneralRe: Great stuff!memberanothermxw4-Apr-04 19:08 
    GeneralRe: Great stuff!sussAnonymous5-Apr-04 14:18 
    GeneralNo with Dialogmembermojster17-May-03 5:42 
    GeneralAlgorithm CodememberJack Rabbit27-Feb-03 17:34 
    GeneralRe: Algorithm CodememberHenry P.27-Feb-03 17:57 
    GeneralRe: Algorithm CodememberJack Rabbit28-Feb-03 19:38 
    GeneralRe: Algorithm CodesussAnonymous3-Mar-03 6:27 
    GeneralRe: Algorithm CodememberJack Rabbit8-Mar-03 4:50 
    GeneralRe: Algorithm CodememberHenry P.31-Mar-03 19:22 
    GeneralRe: Algorithm CodememberB2kguga25-Feb-07 10:04 
    GeneralWin95/98/ME vs. WinNT/2000/XPmemberHenry P.27-Feb-03 16:57 
    GeneralRe: Win95/98/ME vs. WinNT/2000/XPmemberChristian Graus27-Feb-03 17:57 
    GeneralRe: Win95/98/ME vs. WinNT/2000/XPmemberHenry P.3-Mar-03 9:21 
    GeneralRe: Win95/98/ME vs. WinNT/2000/XPmemberChristian Graus3-Mar-03 9:29 

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

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