Does HDC use alpha channel?

Posted by Crend King on Stack Overflow See other posts from Stack Overflow or by Crend King
Published on 2010-02-25T19:34:34Z Indexed on 2010/05/30 5:22 UTC
Read the original article Hit count: 476

Filed under:
|
|
|
|

Hello. Is there a way I can determine if an HDC uses alpha channel? I read Question 333559 and Question 685684, but their questions are about BITMAP. Apparently, some HDC has alpha channel (though they may not use it. Call this "Type 1") while others do not ("Type 2"). I know this by doing the following:

Given a HDC,

  1. Create a compatible DC, and create a DIB section. Select the created HBITMAP into the compatible DC.

  2. BitBlt the source HDC to the compatible DC. Now examine the DIB section bits. For type 2 HDC, after every 3 bytes there is a byte always 0 (like 255 255 255 0); for type 1, these bytes are usualy 255 (like 250 240 230 255). To avoid false positive, I memset the bits to all 0x80 prior to the calls.

  3. Use GetDIBits directly on the source HDC, specify the HBITMAP as GetCurrentObject(hdc, OBJ_BITMAP). For both types of HDC, the 4th bytes are always 0.

  4. Change the DC bitmap by calling ExtTextOut. For type 2, ExtTextOut always set the 4th bytes to 0. For type 1, ExtTextOut always leave them untouched.

I also noticed that the source HDC that are created by APIs (CreateCompatibleDC(), BeginPaint() ...) are always type 2. Type 1 HDC are from standard controls (like menu text). Even the HDC I CreateCompatibleDC from a type 1 becomes a type 2.

So, on one hand, I'm frustrated that Microsoft does not provide equal information to developers (another example may be that you cannot know the direction of a HBITMAP after it is created), on the other hand, I'm still wondering is there a way to distinguish these HDC.

Thanks for help.

© Stack Overflow or respective owner

Related posts about Windows

Related posts about bitmap