Click here to Skip to main content
15,881,866 members
Articles / Programming Languages / C++
Article

Transparent DC class library

Rate me:
Please Sign up or sign in to vote.
1.37/5 (13 votes)
14 Jun 20062 min read 30.4K   482   20   4
A class library of transparent DC

Transparent DC class library


Download source file 130K

Introduction

The library class file is lib\TransparentDC.h inside zipped source file.

The class contains two public static functions, which can blt dc to dc transparently.
They are target to Win32, so you can use them in both Win32 and MFC.

Signatures: 

  1. BOOL BitBlt( HDC hdcDes,int iDesX,int iDesY,
    HDC hdcSrc,int iSrcX,int iSrcY,int iSrcW,int iSrcH,
    COLORREF clrTransparent);
  2. BOOL StretchBlt(HDC hdcDes,int iDesX,int iDesY,int iDesW,int iDesH,
    HDC hdcSrc,int iSrcX,int iSrcY,int iSrcW,int iSrcH,
    COLORREF clrTransparent);
The 2 functions are similar to Win32 related functions, please reference Visual C++ documents for more.

Parameters
  • iDesX,int iDesY,int iDesW,int iDesH
    Destination DC's left, top positions, width and height respectively.
  • iSrcX,int iSrcY,int iSrcW,int iSrcH
    Source DC's left, top positions, width and height respectively.
  • clrTransparent
    Transparence color
Performances
  • They are slower than un-transparent functions
    So please use in slow cases, such as printing, displaying a few of graphics.
  • Valid for common map-mode
    But StretchBlt() doesn't work for MM_HIMETRIC, it may be fixed later if I have time.

Sample

Image 1

This is a MFC sample.
There is only one memory DC inside code, whose bitmap is loaded from resource by LoadBitmap() function.

Colorful big rectangle in the middle of Fig above
The rectangle is paint area for testing both normal DC and transparent DC functions.
Its appearance (color) can be changed by right combo-box: Background, so you can see transparence easily.

Top row in the colorful big rectangle
The row contains 2 blt results by normal DC from memory DC.
Left one is by BitBlt(), right one is by StretchBlt().
Resource bitmap is in size 32x32 as left one.

Bottom row in the colorful big rectangle
The row contains 2 blt results by transparent DC from memory DC.
Left one is by BitBlt(), right one is by StretchBlt().
You can see white color is transparence from right one clearly.

Combo-boxes at right side
  1. MapMode
    Used for changing MapMode of DCs by SetMapMode() function.
  2. Background
    Used for changing background of paint area.
  3. Transparent color
    Used for selecting transparent color of transparent DC.

Result so far:

Transparent StretchBlt() and BitBlt() have benn further modified and implemented in our product: Paper Label Maker - a topmost software in the world, which allows any more transparent colors in theory.
In practice, Paper Label Maker sets the number of transparent colors as "only" 30,  it is also printable rather than just viewable in screen!
Unfortuanately, I can not offer source code of advanced one for you, why don't you modify it yourself?
  



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


Written By
Web Developer
Australia Australia

Please visit our Download Home to obtain many interesting software for free ...


Comments and Discussions

 
GeneralNo comments! [modified] Pin
CoreyCooper18-Jun-07 9:58
CoreyCooper18-Jun-07 9:58 
GeneralDownload Link doesnt work Pin
KarstenK15-Jun-06 0:35
mveKarstenK15-Jun-06 0:35 
GeneralRe: Download Link doesnt work Pin
includeh1015-Jun-06 2:31
includeh1015-Jun-06 2:31 
GeneralRe: Download Link doesnt work Pin
KarstenK15-Jun-06 3:33
mveKarstenK15-Jun-06 3:33 

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

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