Transparent Blts in Windows NT

Last reviewed: November 2, 1995
Article ID: Q89375
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.1, 3.5, and 3.51
    

SUMMARY

In order to perform a transparent blt in Microsoft Windows versions 3.0 and 3.1, the BitBlt() function must be called two or more times. This process involves nine steps. (For more information on this process, see article Q79212 in the Microsoft Knowledge Base.)

Windows NT introduces a new method of achieving transparent blts. This method involves the use of the MaskBlt() function. The MaskBlt() function lets you use any two arbitrary ROP3 codes (say, SRCCOPY and BLACKNESS) and apply them on a pel-by-pel basis using a mask.

MORE INFORMATION

For this example, the source and target bitmaps contain 4 BPP. The call to the MaskBlt() function is as follows:

   MaskBlt(hdcTrg,  // handle of target DC
                0,  // x coord, upper-left corner of target rectangle
                0,  // y coord, upper-left corner of target rectangle
               15,  // width of source and target rectangles
               15,  // height of source and target rectangles
           hdcSrc,  // handle of source DC
                0,  // x coord, upper-left corner of source rectangle
                0,  // y coord, upper-left corner of source rectangle
          hbmMask,  // handle of monochrome bit-mask
                0,  // x coord, upper-left corner of mask rectangle
                0,  // y coord, upper-left corner of mask rectangle
       0xAACC0020   // raster-operation (ROP) code
                );

The legend is as follows

   '.' = 0,
   '@' = 1,
   '+' = 2,
   '*' = 3,
   '#' = 15

Source Bitmap      Mask Bitmap        Target Bitmap      Result

***+++***+++***    .......@.......    ###############    #######*#######
***+++***+++***    ......@@@......    ###############    ######***######
***+++***+++***    .....@@@@@.....    ##...........##    ##...+***+...##
+++***+++***+++    ....@@@@@@@....    ##...........##    ##..**+++**..##
+++***+++***+++    ...@@@@@@@@@...    ##...........##    ##.***+++***.##
+++***+++***+++    ..@@@@@@@@@@@..    ##...........##    ##+***+++***+##
***+++***+++***    .@@@@@@@@@@@@@.    ##...........##    #**+++***+++**#
***+++***+++***    @@@@@@@@@@@@@@@    ##...........##    ***+++***+++***
***+++***+++***    .@@@@@@@@@@@@@.    ##...........##    #**+++***+++**#
+++***+++***+++    ..@@@@@@@@@@@..    ##...........##    ##+***+++***+##
+++***+++***+++    ...@@@@@@@@@...    ##...........##    ##.***+++***.##
+++***+++***+++    ....@@@@@@@....    ##...........##    ##..**+++**..##
***+++***+++***    .....@@@@@.....    ##...........##    ##...+***+...##
***+++***+++***    ......@@@......    ###############    ######***######
***+++***+++***    .......@.......    ###############    #######*#######

Note that the ROP "AA" is applied where 0 bits are in the mask and the ROP "CC" is applied where 1 bit is in the mask. This a transparency.

When creating a ROP4, you can use the following macro:

   #define ROP4(fore,back) ((((back) << 8) & 0xFF000000) | (fore))

This macro can be used to call the MaskBlt() function as follows:

   MaskBlt(hdcDest, xTrgt, yTrgt,
                          cx, cy,
              hdcSrc, xSrc, ySrc,
           hbmMask, xMask, yMask,
        ROP4(PATCOPY, NOTSRCCOPY)
                               );

This call would draw the selected brush where 1 bit appears in the mask and bitwise negation of the source bitmap where 0 bits appear in the mask.


Additional reference words: 3.10 3.50 pixel
KBCategory: kbgraphic
KBSubcategory: GdiBmp


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.