Solved

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

Posted on 1997-08-13
3
422 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now