Solved

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

Posted on 1997-08-13
3
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wait notify demo infinite loop 3 148
MaxSpan challenge 9 138
"Black Box" Testing of Control System Software 2 125
Problem to App 4 145
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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