用picturebox.hdc不行,因为给挡住了,请大家给点源码,vb水平不行啊

解决方案 »

  1.   

    先hide那个控件,再操作,最后恢复。
      

  2.   

    Public Sub HookToLV(ByVal hwnd As Long, ByVal hdcSource As Long, ByVal hdcTest As Long, ByVal B As Boolean)
        If B Then
            origLVwinProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf LVSubcls_WProc4Hdr)
            m_hooked_lv = hwnd
            glHdrBkClr = vbYellow
            glHdrTextClr = vbRed
            sourceImagedc = hdcSource
            m_testdc = hdcTest
        Else
            Call SetWindowLong(m_hooked_lv, GWL_WNDPROC, origLVwinProc)
        End If
    End Sub
    Private Sub Invalidate()
        Dim rc As RECT
        Dim bErase As Long
        bErase = 0
        GetWindowRect m_hooked_lv, rc
        InvalidateRect m_hooked_lv, rc, bErase
    End Sub
    Private Sub Combine()
        Dim BF As BLENDFUNCTION, lBF As Long
         With BF
         .BlendOp = AC_SRC_OVER
         .BlendFlags = 0
         .SourceConstantAlpha = 50
         .AlphaFormat = 0
          End With
        RtlMoveMemory lBF, BF, 4
         
        Dim hMemDC As Long
        Dim LvDC As Long
        Dim hBitmap As Long, obj As Long
        LvDC = GetDC(m_hooked_lv)
        hMemDC = CreateCompatibleDC(LvDC)
        hBitmap = CreateCompatibleBitmap(LvDC, 100, 100)
        obj = SelectObject(hMemDC, hBitmap)
        Dim re As Long
        'Call SendMessage(m_hooked_lv, &H14, LvDC, 0&)
        'Call SendMessage(m_hooked_lv, &HF, LvDC, 0&)
        
        re = BitBlt(hMemDC, 0, 0, 100, 100, LvDC, 0, 0, SRCCOPY)
        re = AlphaBlend(hMemDC, 0, 0, 300, 300, sourceImagedc, 0, 0, 300, 300, lBF)
        re = BitBlt(LvDC, 0, 0, 300, 300, hMemDC, 0, 0, SRCCOPY)
       're = BitBlt(LvDC, 0, 0, 300, 300, sourceImagedc, 0, 0, SRCCOPY)
        re = BitBlt(m_testdc, 0, 0, 100, 100, hMemDC, 0, 0, SRCCOPY)
           
        DeleteObject obj
        DeleteObject hBitmap
        DeleteDC hMemDC
        ReleaseDC m_hooked_lv, LvDC    
    End Sub
    Public Function LVSubcls_WProc4Hdr(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        On Error Resume Next
        Dim tMessage As NMHDR
        Dim lCode As Long
        Dim tLVRedrawMessage As NMLVCUSTOMDRAW
        Select Case msg
            Case WM_VSCROLL
                LVSubcls_WProc4Hdr = CallWindowProc(origLVwinProc, hwnd, msg, wParam, lParam)
                'Combine
                Exit Function
            Case WM_HSCROLL
                LVSubcls_WProc4Hdr = CallWindowProc(origLVwinProc, hwnd, msg, wParam, lParam)
                'Combine
                Exit Function
            Case WM_PAINT
                Invalidate
                LVSubcls_WProc4Hdr = CallWindowProc(origLVwinProc, hwnd, msg, wParam, lParam)
                Combine
                Exit Function        Case Else
                LVSubcls_WProc4Hdr = CallWindowProc(origLVwinProc, hwnd, msg, wParam, lParam)
        End SelectEnd Function
    如何在Combine函数前得到listview原来的dc啊,现在得到的是刷新前的
    即上次经过透明化后的dc,所以下次点击listview的滚动条再刷新就变成了透明越来越低了
      

  3.   

    用两个picturebox控件。一个按钮Command1一个label1
    picture1作为源控件
    picture2用作显示被遮住的图像部分
    label1放在picture1中遮住部分图像添加代码
    Private Sub Command1_Click()
        Picture2.PaintPicture Picture1.Picture, 0, 0, , , Label1.Left, Label1.Top, Label1.Width, Label1.Height
    End Sub测试了。。可以
    在pic2中显示pic1中被label1遮住的图像部分
      

  4.   

    那怎么样让listview进行重绘阿,我用一下语句:
    SendMessage listview.hwnd, WM_PAINT, drawDC1, ByVal 0&
    BitBlt Picture1.hDC, 0, 0, TVWidth, TVHeight, drawDC1, 0, 0, vbSrcCopy发现显示在Picture1上的东西不是listview的全部图像,只有一点点
      

  5.   

    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:\Blue hills.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'    Dim Item As ListItem
    '    List1.View = lvwReport
    '    Dim nLen As Long
    '    nLen = List1.Width / (7)
    '    Dim i As Integer, j As Integer
    '    Call List1.ColumnHeaders.Clear
    '    Call List1.ColumnHeaders.Add(, , "Êý¾Ý", nLen, lvwColumnLeft)
    '    For i = 1 To 6
    '        Call List1.ColumnHeaders.Add(, , "µÚ" & i & "ÁÐ", nLen, lvwColumnCenter)
    '    Next
    '
    '    For i = 1 To 40
    '        Set Item = List1.ListItems.Add(, , "µÚ" & i & "ÐÐ1")
    '        For j = 0 To 6
    '             Item.ListSubItems.Add , , CInt(Rnd * 1000) 'Ìí¼ÓÊý¾Ý
    '        Next
    '        For j = 1 To 2
    '            List1.ListItems(i).ListSubItems.Item(j).ForeColor = vbBlue
    '        Next
    '
    '        For j = 3 To 6
    '            List1.ListItems(i).ListSubItems.Item(j).ForeColor = vbRed
    '        Next
    '    NextCall SubClassListBox(True, Picture1, List1, Picture2)
    List1.RefreshEnd SubPrivate Sub Form_Unload(Cancel As Integer)
    Call SubClassListBox(False, Picture1, List1, Picture2)
    End Sub
      

  6.   

    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 LongPublic Function SubClassListBox(OnOff As Boolean, _
    ContainerControl As PictureBox, ListCtl As ListView, 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 FunctionPublic 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 FunctionPublic 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
      

  7.   

    透明的LISTBOX,但是对LISTVIEW不行谁知道WHY