mfc >> Background image or transparency in ListBox

by German » Tue, 25 Nov 2003 00:01:37 GMT

Hi.
I'm looking for some ListBox derived class that give me en opportunity to
make my ListBox transparent (I have a background on my dialog and want to
make only text visible and selectable on my ListBox) or set some background
image to ListBox so the only text will be visible (with no white rectangle
on background).
Do you now something like that? Of course first of all I tried google to
help me, but search gave me useless results.
Thanks.

German Koninin

---------------------------------------------------------------------
For every complex problem, there's solution that is simple, neat and
wrong...




mfc >> Background image or transparency in ListBox

by David A. Mair » Tue, 25 Nov 2003 00:39:28 GMT





background

The simplest way to get a window that is transparent is to not paint its
background. You could try implementing a do nothing WM_ERASEBKGND handler.
I haven't tried this but it seems obvious to me. The only problem I can see
would be if there are any controls that paint some of their "structural"
components when erasing the background, i.e. borders, headings, buttons,
etc. FWIW, I doubt that there are (m)any controls that paint their layount
when doing an erase background. If you want to do something like alpha
blending (semi-transparency) you'll have to research it but for small
windows it can obviously be done in a WM_ERASEBKGND handler by simply
averaging the control background and the dialog beneath the control. You
may need to force the parent to re-paint (with a clip rectangle) when doing
an erase background to avoid problems with text removed from a list not
erasing when removed (due to you not really painting the packground). IIRC,
there is a transparent extended window style but some of the reading I've
been doing suggests it may not be supported by controls. If it is and you
can use CreateWindowEx then you might avoind that problem by simply
indicating that the window is transparent and let window send paint messages
in the correct order to achieve your goal.





mfc >> Background image or transparency in ListBox

by German » Tue, 25 Nov 2003 17:37:08 GMT

This is not right.
I know that the easiest way is to overwrite OnEraseBkgnd function, but this
is not working in ListBox.
that's why I ask my question here.





to
to
rectangle
handler.
see
layount
doing
IIRC,
messages




Similar Threads

1. Background Image in Listbox

Hi,

Is it possible to put a background image in a listBox control?? How can
this be done? Specifically I would like to display an image in the are
of a listbox which is not occuppied by any listbox items (alternatively
if I could get rid of this region altogether or make it transparent..
just thinking..) Can anyone help???

Thanks in advance
Kits

2. Application with background image and several images on top of it - CSharp/C#

3. gdi+ newbie: image transparency

Let's say I have 2 images A and B: if I want to display B over A with a
varying level of transparency, I can use a matrix to change the alpha value
e.g.

    // ... draw image A ...
    ColorMatrix cm = new ColorMatrix();
    cm.Matrix33 = 50;    // 50% opacity
    ImageAttributes ia = new ImageAttributes();
    ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
    // ...draw image B using attributes ia...

Besides this, I'd also like to treat a single color value in B as a the
transparent color: i.e. if the B image has a black circle onto a white
background, I'd like to treat white (rgb FFFFFF) as fully transparent,
independently from the transparency value chosen for blending B with A (the
circle will be drawn onto A with the specified transparency level and its
white background will not be visible at all). How can I do this?

Thanks guys!


4. image color transparency - CSharp/C#

5. Large image slow refresh transparency control

6. png image and transparency - CSharp/C#

7. Image Transparency in overlapping PictureBox objects.

I am making an application that streams video from a web camera onto the 
client area of a PictureBox on a Windows CLR Form in MS Visual Studio 2005 
(using C++).
The streaming video works fine, and now I am trying to create an image 
overlay.
I am assuming that the best way for me to do this is to create a second 
PictureBox that lays over the streaming video. I would then need to draw 
directly into the bitmap shown in the overlaying PictureBox and have most of 
the pixels in that image be transparent (i.e. showing the streaming video 
from the underlying picturebox). I have attempted to create a class called 
myPictBox that inherits from PictureBox and overrides both the OnPaint and 
OnPaintBackground methods, but I really don't know what I am doing. I think 
what I want to do is essentially equivalent to the problem of creating a 
nonrectangular custom control, though I will not need to respond to mouse 
click events as a form control would.

Can anyone offer me any suggestions about this problem?
Am I on the right track, at least?

A stripped down version of how I think this should be solved is shown below 
(as is suggested by an article in the MSDN forums). This code results in a 
black rectangle overlaying my video stream.

------ File: MyPictBox.h ----------------------
pragma once
#pragma managed

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace v1 {
   public ref class MyPictBox: public PictureBox {
      protected: virtual property CreateParams^ CreateParams {
         CreateParams^ get () override {
            CreateParams^ cp = __super::CreateParams;
            cp->ExStyle |= 0x20;  // WS_EX_TRANSPARENT
            return cp;
         }
      }
      protected: virtual void OnPaintBackground(PaintEventArgs^ pevent) 
override {
         // Don't paint the background.
      }
      protected: virtual void OnPaint(PaintEventArgs^ pe) override {
         // Paint background image
         if (this->BackgroundImage != nullptr) {
            Bitmap^ bmp = gcnew Bitmap(this->BackgroundImage);
            bmp->MakeTransparent(Color::White);
            pe->Graphics->DrawImage(bmp, 0, 0);
         }
         // Draw opaque portion of control
         Pen^ myPen = gcnew Pen(Color::Red,3.0f);
         Point point1 = Point(0,50);
         Point point2 = Point(50,50);
         pe->Graphics->DrawLine(myPen, point1, point2);
         delete myPen;
      }
   }; // class MyPictBox
} // namespace v1
-----------------------------------------------

8. CListCtrl and subitem image transparency