Transparent Blts in Windows NT (89375)
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API), when used with:
- the operating system: Microsoft Windows NT 3.1
- the operating system: Microsoft Windows NT 3.5
- the operating system: Microsoft Windows NT 3.51
This article was previously published under Q89375 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
79212 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.
Modification Type: | Major | Last Reviewed: | 3/15/2004 |
---|
Keywords: | KB89375 |
---|
|