Solved

Deriving a CStatic so it will not paint a specific color...

Posted on 1997-08-13
3
425 Views
Last Modified: 2013-11-20
I want to derive a CStatic class so that it will not display a specific color when  a bitmap is assigned to it.  Should I do this in OnPaint()?  Basically, I've got some bitmaps with a white background that I want to make transparent when it is displayed in a CStatic control.

Source examples are needed and appreciated.

Thanks in advance,
   Dave
0
Comment
Question by:David Gray
  • 2
3 Comments
 

Accepted Solution

by:
kaelin earned 100 total points
ID: 1303699
Dave,

You cannot derive and do your own drawing with a CStatic control,
because the underlying Windows control does not support an
owner-draw flag.  You could do a CButton or CListCtrl, however
there's not much point in deriving from any of these anyway
because a CStatic control is the simplest control there is.
Just make your own replacement class derived directly from CWnd,
and then draw your bitmap from OnPaint.

"Masking" the image to make one color transparent is another
matter.  The easiest way to do this is to convert your bitmaps
to icons and then use CDC::DrawIcon to paint them.  What an
icon has that a bitmap lacks is a mask, which is simply an extra
1-bit deep bitmap where off bits are treated as transparent
parts of the image.  You can easily convert bitmaps to icons
using Developer Studio's resource editor.  Create a new icon resource of the desired size, and then paste the bitmap from the
clipboard and change the areas you want transparent to the
icon's "background" color in the editor.

If for some reason you don't want to let DrawIcon do all the
work, the function to check out is CDC::BitBlt.  It will take
multiple BitBlt calls to do the same thing, with various ROP
codes in a specific order (I don't recall the details off the
top of my head).

I hope you find these tips useful.
0
 

Author Comment

by:David Gray
ID: 1303700
How can you make a icon of a desired size to fit the the size of the bitmap, when I tried before it seemed like it would only let me have the standard 32x32 size.  If I could use the icon class to display bitmaps, this is a totally acceptable solution, if you know a way to make the allowable size for an icon larger.

0
 

Author Comment

by:David Gray
ID: 1303701
Never mind my previous comment, I just discovered the way to customize the size of an icon.  I never noticed the little toolbar icon that allows you to choose a specific size.

Thanks for you help,
    Dave
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 84
sameEnds challenge 3 160
no14 challenge 14 69
Fibonacci challenge 11 124
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question