Solved

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

Posted on 1997-08-13
3
428 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 111
how do i create updater to My Activex application? 3 101
Expand macro to ask for filename column 8 37
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 115
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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