Prev: Run-time error '4100': Business object cannot be created
Next: Problem with Terminal service virtual channel on VB6
From: JP Bless on 17 Aug 2007 20:55 Is there any way... API to make ListView control transaparent. I am using V6SP6. Thanks in advance.
From: DanS on 17 Aug 2007 23:18 "JP Bless" <jp3BlessNoSpam(a)hotmail.com> wrote in news:OBIiJKT4HHA.600(a)TK2MSFTNGP05.phx.gbl: > Is there any way... API to make ListView control transaparent. I am > using V6SP6. Thanks in advance. No. I haven't found one yet. The only way to make it transparent, is to set the forms' extended window style to WS_EX_LAYERED, and set the background color of the listview to something you won't see too often, like solid vbMagenta. You can then call SetLayeredWindow attributes on your form, passing vbMagenta as the transparent color, and this will make any pixel colored vbMagenta transparent, of which you have already set the listview to. The caveat here is that since layered windows operate on the entire form, the listview will become transparent all the way down to the desktop, just like using regioning to draw irregular forms. Because of this, the transparent area is not part of the listview and does not respond to standard listview events. You can add listitems obviously, but those will be a mess too. The transparency-via-the-layered-window-technique does not display icons with alpha channels well at all. Maybe there's another way. What are you trying to do ?
From: Mike Williams on 18 Aug 2007 05:45 "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 ' *** 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: JP Bless on 18 Aug 2007 08:40 What I am trying to do... I have a form with (background) picture; I have a list view on the form that blocks the picture. Looks awkward. I am trying to make the listview transparent so the whole picture on the firm could be seen. Thanks for your help. "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:Xns998FEE0618530thisnthatadelphianet(a)216.196.97.142... > "JP Bless" <jp3BlessNoSpam(a)hotmail.com> wrote in > news:OBIiJKT4HHA.600(a)TK2MSFTNGP05.phx.gbl: > >> Is there any way... API to make ListView control transaparent. I am >> using V6SP6. Thanks in advance. > > No. I haven't found one yet. > > The only way to make it transparent, is to set the forms' extended window > style to WS_EX_LAYERED, and set the background color of the listview to > something you won't see too often, like solid vbMagenta. > > You can then call SetLayeredWindow attributes on your form, passing > vbMagenta as the transparent color, and this will make any pixel colored > vbMagenta transparent, of which you have already set the listview to. > > The caveat here is that since layered windows operate on the entire form, > the listview will become transparent all the way down to the desktop, > just like using regioning to draw irregular forms. Because of this, the > transparent area is not part of the listview and does not respond to > standard listview events. > > You can add listitems obviously, but those will be a mess too. The > transparency-via-the-layered-window-technique does not display icons with > alpha channels well at all. > > Maybe there's another way. What are you trying to do ? > > > > > >
From: JP Bless on 18 Aug 2007 08:42 Thanks Mike... I appreciate your help. "Mike Williams" <mikea(a)whiskyandCoke.com> wrote in message 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 > > ' *** 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 *** > > >
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Run-time error '4100': Business object cannot be created Next: Problem with Terminal service virtual channel on VB6 |