From: DanS on
"Mike Williams" <mikea(a)whiskyandCoke.com> wrote in
news:eXho9xX4HHA.1992(a)TK2MSFTNGP03.phx.gbl:

> "JP Bless" <jp3BlessNoSpam(a)hotmail.com> wrote in message
> news:OBIiJKT4HHA.600(a)TK2MSFTNGP05.phx.gbl...
>
>> Is there any way... API to make ListView control transaparent.
>> I am using V6SP6. Thanks in advance.
>
> Here's a transparent ListBox. You might be able to use the same
> technique on a ListView control. You can set the translucency to
> anything in the range 0 (fully transparent) to 255 (fully opaque). The
> code is a modified version of something I found on one of the
> newsgroups a while back. It's quite nice. You'll need a standard code
> module and a Form containing one ListBox and two Picture Boxes:
>
> Mike

It may be me (most likely) but your sample code did not seem to work
here. I see the picture being set as the form picture, but no
transparent/lucent listbox.

All I did was copy & paste, added the required controls, and then change
the path/file being loaded.

(Subsequently tried changing the value in the BF struct, where the rem's
mentiuon a 0 to 255 value, and nothing.)

I was hoping......


Regards,

DanS


> ' *** START OF FORM CODE ***
> Option Explicit
> Private Sub Form_Load()
> Me.Show
> Dim BF As BLENDFUNCTION, lBF As Long
> Dim p1 As StdPicture, n As Long
> Me.WindowState = vbMaximized
> Picture2.BorderStyle = vbBSNone
> Picture2.AutoRedraw = True
> Picture2.ScaleMode = vbPixels
> Picture2.Visible = False
> Picture1.BorderStyle = vbBSNone
> Picture1.AutoRedraw = True
> Picture1.ScaleMode = vbPixels
> Me.AutoRedraw = True
> Me.ScaleMode = vbPixels
> Set p1 = LoadPicture("c:\temp\tulips.jpg")
> Me.PaintPicture p1, 0, 0, Me.ScaleWidth, Me.ScaleHeight
> ' Note that the ListBox font size is set here *before*
> ' setting the height of the picture box to the same as
> ' the height of the ListBox. This is because if a ListBox
> ' has its IntegralHeight property set to True (as is usually
> ' the case) then its height will usually change when you
> ' change the size of the font. If later in the program code
> ' you decide to change the font size in the listbox to a
> ' new value then you must follow that by changing the picture
> ' box size again just in case the height of the listbox
> ' changes.
> Picture1.Left = List1.Left
> Picture1.Top = List1.Top
> Set List1.Container = Picture1
> List1.Font.Name = "Arial"
> List1.Font.Bold = True
> List1.Font.Size = 10
> Picture2.Height = List1.Height
> Picture2.Width = List1.Width
> Picture1.Width = Picture2.Width
> Picture1.Height = Picture2.Height
> List1.Left = 0: List1.Top = 0
> Picture2.PaintPicture Me.Image, 0, 0, _
> List1.Width, List1.Height, Picture1.Left + 2, _
> Picture1.Top + 2, List1.Width, List1.Height
> ' set picture1 backcolor to a colour that contrasts
> ' with the text colour of the ListBox (for example
> ' set it to white if using black text in the ListBox)
> Picture1.BackColor = vbWhite
> ' now blend a copy of the appropriate part of the
> ' background image with picture1 background colour
> With BF
> .BlendOp = AC_SRC_OVER
> .BlendFlags = 0
> ' set the following value in the range 0 to 255
> ' depending on required "translucency". Zero is full
> ' original image colours (fully transparent) and
> ' 255 is whatever colour picture1 background has
> ' been set to (fully opaque). This example uses
> ' the value 0 (fully transparent)
> .SourceConstantAlpha = 0 ' (0 to 255)
> .AlphaFormat = 0
> End With
> Caption = "Blend set to 80 (white tracing paper)"
> RtlMoveMemory lBF, BF, 4
> ' blend the "full colour" background with a percentage
> ' of the backcolour of picture1 (if desired)
> AlphaBlend Picture2.hdc, 0, 0, Picture2.Width, Picture2.Height, _
> Picture1.hdc, 0, 0, Picture2.Width, Picture2.Height, lBF
> For n = 1 To 200
> List1.AddItem Format(n) & " " & "Rum and Coke"
> Next n
> Call SubClassListBox(True, Picture1, List1, Picture2)
> List1.Refresh
> End Sub
>
> Private Sub Form_Unload(Cancel As Integer)
> Call SubClassListBox(False, Picture1, List1, Picture2)
> End Sub
> ' *** END OF FORM CODE ***
> '
> ' *** START OF MODULE CODE ***
> Option Explicit
> Public Declare Function AlphaBlend Lib "msimg32.dll" _
> (ByVal desthDC As Long, _
> ByVal destX As Long, ByVal destY As Long, _
> ByVal destWidth As Long, ByVal destHeight As Long, _
> ByVal srchDC As Long, _
> ByVal srcX As Long, ByVal srcY As Long, _
> ByVal srcWidth As Long, ByVal srcHeight As Long, _
> ByVal BLENDFUNCT As Long) As Long
> Public Const AC_SRC_OVER = &H0
> Public Type BLENDFUNCTION
> BlendOp As Byte
> BlendFlags As Byte
> SourceConstantAlpha As Byte
> AlphaFormat As Byte
> End Type
> Private Declare Function InvalidateRect Lib "user32" _
> (ByVal hwnd As Long, ByVal lpRect As Long, _
> ByVal bErase As Long) As Long
> Private Declare Function CreatePatternBrush Lib "gdi32" _
> (ByVal hBitmap As Long) As Long
> Private Declare Function DeleteObject Lib "gdi32" _
> (ByVal hObject As Long) As Long
> Private Declare Function SetBkMode Lib "gdi32" _
> (ByVal hdc As Long, ByVal nBkMode As Long) As Long
> Public Declare Sub RtlMoveMemory Lib "kernel32.dll" _
> (Destination As Any, Source As Any, ByVal Length As Long)
> Private Declare Function CallWindowProc Lib "user32" _
> Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
> ByVal hwnd As Long, ByVal Msg As Long, _
> ByVal wParam As Long, ByVal lParam As Long) As Long
> Private Declare Function GetWindowLong Lib "user32" _
> Alias "GetWindowLongA" (ByVal hwnd As Long, _
> ByVal nIndex As Long) As Long
> Private Declare Function SetWindowLong Lib "user32" _
> Alias "SetWindowLongA" (ByVal hwnd As Long, _
> ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
> Private Const GWL_WNDPROC = (-4)
> Private Const WM_ERASEBKGND = &H14
> Private Const WM_KEYDOWN = &H100
> Private Const WM_VSCROLL = &H115
> Private Const WM_CTLCOLORLISTBOX = &H134
> Private Const TRANSPARENT = 1
> Private Const OPAQUE = 2
> Private OldContainerProc As Long
> Private OldListBoxProc As Long
> Private BackgroundBrush As Long
> Private ContainerWnd As Long
> Private ListBoxWnd As Long
>
> Public Function SubClassListBox(OnOff As Boolean, _
> ContainerControl As PictureBox, ListCtl As ListBox, _
> PicBack As PictureBox) As Long
> If OnOff = True Then
> ContainerWnd = ContainerControl.hwnd
> ListBoxWnd = ListCtl.hwnd
> BackgroundBrush = CreatePatternBrush(PicBack.Image.Handle)
> OldContainerProc = SetWindowLong(ContainerControl.hwnd, _
> GWL_WNDPROC, AddressOf ContainerProc)
> OldListBoxProc = SetWindowLong(ListCtl.hwnd, _
> GWL_WNDPROC, AddressOf ListBoxProc)
> Else
> SetWindowLong ContainerControl.hwnd, GWL_WNDPROC, _
> OldContainerProc
> SetWindowLong ListCtl.hwnd, GWL_WNDPROC, _
> OldListBoxProc
> End If
> End Function
>
> Public Function ContainerProc(ByVal hwnd As Long, _
> ByVal uMsg As Long, ByVal wParam As Long, _
> ByVal lParam As Long) As Long
> If (hwnd = ContainerWnd) And (uMsg = WM_CTLCOLORLISTBOX) _
> And (BackgroundBrush <> 0) Then
> SetBkMode wParam, TRANSPARENT
> 'allow the old process to set original text colour
> CallWindowProc OldContainerProc, hwnd, uMsg, wParam, lParam
> ' change brush
> ContainerProc = BackgroundBrush
> Else
> ContainerProc = CallWindowProc(OldContainerProc, _
> hwnd, uMsg, wParam, lParam)
> End If
> End Function
>
> Public Function ListBoxProc(ByVal hwnd As Long, _
> ByVal uMsg As Long, ByVal wParam As Long, _
> ByVal lParam As Long) As Long
> If uMsg = WM_VSCROLL _
> Or uMsg = WM_KEYDOWN Then
> InvalidateRect hwnd, 0, 0
> ListBoxProc = CallWindowProc(OldListBoxProc, _
> hwnd, uMsg, wParam, lParam)
> ElseIf uMsg = WM_ERASEBKGND Then
> ListBoxProc = 1
> Else
> ListBoxProc = CallWindowProc(OldListBoxProc, _
> hwnd, uMsg, wParam, lParam)
> End If
> End Function
> ' *** END OF MODULE CODE ***
>
>
>
>

From: Mike Williams on
"DanS" <t.h.i.s.n.t.h.a.t(a)a.d.e.l.p.h.i.a.n.e.t> wrote in message
news:Xns99906AF3F88ADthisnthatadelphianet(a)216.196.97.142...

> Mike. It may be me (most likely) but your sample code did not
> seem to work here. I see the picture being set as the form picture,
> but no transparent/lucent listbox. All I did was copy & paste,
> added the required controls, and then change the path/file being loaded.

I wonder why that is happenning? What do you see? Do you see a standard
ListBox with 200 entries using a standard white background? I've tried the
exact code I posted on at least three WinXP machines a long time ago, and it
worked fine, with the ListBox fully scrollable and with its background being
transparent so I can see the Form's image beneath it. Since then I've tried
it on my desktop machine and on a new laptop, both running Windows Vista
(one the Business edition and one the Ultimate edition) and it works fine on
those machines as well. It also works whether or not Aero is running. I've
also just tried using different desktop settings (different colour depths
and stuff) and it still works fine. Perhaps there's a problem in the code
somewhere, but if there is I can't see it at the moment. Perhaps other
people here will report whether or not it works on their own systems?

Mike


From: Steve Gerrard on

"Mike Williams" <mikea(a)whiskyandCoke.com> wrote in message
news:ONs0Oec4HHA.1208(a)TK2MSFTNGP05.phx.gbl...
> "DanS" <t.h.i.s.n.t.h.a.t(a)a.d.e.l.p.h.i.a.n.e.t> wrote in message
> news:Xns99906AF3F88ADthisnthatadelphianet(a)216.196.97.142...
>
>> Mike. It may be me (most likely) but your sample code did not
>> seem to work here. I see the picture being set as the form picture,
>> but no transparent/lucent listbox. All I did was copy & paste,
>> added the required controls, and then change the path/file being loaded.
>
> I wonder why that is happenning? What do you see? Do you see a standard
> ListBox with 200 entries using a standard white background? I've tried the
> exact code I posted on at least three WinXP machines a long time ago, and it
> worked fine, with the ListBox fully scrollable and with its background being
> transparent so I can see the Form's image beneath it. Since then I've tried it
> on my desktop machine and on a new laptop, both running Windows Vista (one the
> Business edition and one the Ultimate edition) and it works fine on those
> machines as well. It also works whether or not Aero is running. I've also just
> tried using different desktop settings (different colour depths and stuff) and
> it still works fine. Perhaps there's a problem in the code somewhere, but if
> there is I can't see it at the moment. Perhaps other people here will report
> whether or not it works on their own systems?
>

Worked fine for me on Windows XP


From: DanS on
"Mike Williams" <mikea(a)whiskyandCoke.com> wrote in
news:ONs0Oec4HHA.1208(a)TK2MSFTNGP05.phx.gbl:

> "DanS" <t.h.i.s.n.t.h.a.t(a)a.d.e.l.p.h.i.a.n.e.t> wrote in message
> news:Xns99906AF3F88ADthisnthatadelphianet(a)216.196.97.142...
>
>> Mike. It may be me (most likely) but your sample code did not
>> seem to work here. I see the picture being set as the form picture,
>> but no transparent/lucent listbox. All I did was copy & paste,
>> added the required controls, and then change the path/file being
>> loaded.
>
> I wonder why that is happenning? What do you see? Do you see a
> standard ListBox with 200 entries using a standard white background?
> I've tried the exact code I posted on at least three WinXP machines a
> long time ago, and it worked fine, with the ListBox fully scrollable
> and with its background being transparent so I can see the Form's
> image beneath it. Since then I've tried it on my desktop machine and
> on a new laptop, both running Windows Vista (one the Business edition
> and one the Ultimate edition) and it works fine on those machines as
> well. It also works whether or not Aero is running. I've also just
> tried using different desktop settings (different colour depths and
> stuff) and it still works fine. Perhaps there's a problem in the code
> somewhere, but if there is I can't see it at the moment. Perhaps other
> people here will report whether or not it works on their own systems?
>
> Mike
>
>

Well I tried it again. New project, added 1 listbox, 2 picture boxes,
changed the name of the image file in the code to load kitty.jpg instead
of what was there....no transparency.

A screenshots here, it looks just like a standard listbox.

http://users.adelphia.net/~thisnthat/screenshot.jpg

I have no idea, this is XP with SP1 only, but still........

DanS
From: Steve Gerrard on

"DanS" <t.h.i.s.n.t.h.a.t(a)a.d.e.l.p.h.i.a.n.e.t> wrote in message
news:Xns9990E2F311D41thisnthatadelphianet(a)216.196.97.142...
> "Mike Williams" <mikea(a)whiskyandCoke.com> wrote in
> news:ONs0Oec4HHA.1208(a)TK2MSFTNGP05.phx.gbl:
>
>
> Well I tried it again. New project, added 1 listbox, 2 picture boxes,
> changed the name of the image file in the code to load kitty.jpg instead
> of what was there....no transparency.
>
> A screenshots here, it looks just like a standard listbox.
>
> http://users.adelphia.net/~thisnthat/screenshot.jpg
>
> I have no idea, this is XP with SP1 only, but still........
>
> DanS

Must be a graphics setting, or a capability of the graphics card, or something
like that.