声明:
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const WS_EX_TRANSPARENT = &H20&
Const GWL_EXSTYLE = (-20)
使用:
retval = SetWindowLong(Form2.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT)
透明效果是出来啦,如果移动的话,屏幕会变乱。这是我在网上看到的,还没有试过,有兴趣试试!
呵呵……

解决方案 »

  1.   

    Private Declare Function SetWindowLong Lib "User" (ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    '
    Const GWL_EXSTYLE = (-20)
    Const WS_EX_TRANSPARENT = &H20&
    Const SWP_FRAMECHANGED = &H20
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1
    Const SWP_SHOWME = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
    Const HWND_NOTOPMOST = -2Public Sub maketransperent(Frm As Object)
    SetWindowLong Frm.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
    SetWindowPos Frm.hwnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, SWP_SHOWME
    End Sub
      

  2.   

    使用SetLayeredWindowAttributes可以方便的制作透明窗体,此函数在w2k以上才支持,而且如果希望直接使用的话,可能需要下载最新的SDK。不过此函数在w2k的user32.dll里有实现,所以如果你不希望下载巨大的sdk的话,可以直接使用GetProcAddress获取该函数的指针。SetLayeredWindowAttributes的函数原型如下:BOOL SetLayeredWindowAttributes(
    HWND hwnd,       // handle to the layered window
    COLORREF crKey,  // specifies the color key
    BYTE bAlpha,     // value for the blend function
    DWORD dwFlags    // action
    ); <Requirements>
    Windows NT/2000/XP: Included in Windows 2000 and later.
    Windows 95/98/Me: Unsupported.(注意了,在win9x里没法使用的)
    Header: Declared in Winuser.h; include Windows.h.
    Library: Use User32.lib. 一些常量:
    WS_EX_LAYERED = 0x80000;
    LWA_ALPHA = 0x2;
    LWA_COLORKEY=0x1
    其中dwFlags有LWA_ALPHA和LWA_COLORKEY
    LWA_ALPHA被设置的话,通过bAlpha决定透明度.
    LWA_COLORKEY被设置的话,则指定被透明掉的颜色为crKey,其他颜色则正常显示.
    要使使窗体拥有透明效果,首先要有WS_EX_LAYERED扩展属性(旧的sdk没有定义这个属性,所以可以直接指定为0x80000). Notice: 2k or xp
      

  3.   

    用SetWindowRgn设置窗口的显示区域!http://www.dapha.net/down/list.asp?id=1969
      

  4.   


    这些方法都不好?
    我想用CombinRgn和SetWindowLong的效果会更好一些。
    合并区域时用RGN_XOR参数,可以达到该效果。
      

  5.   

    自己模拟拖动
    Private tx As Single
    Private ty As SinglePrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        tx = X
        ty = Y
    End If
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        Me.Move Me.Left + X - tx, Me.Top + Y - ty
    End If
    End Sub
      

  6.   

    看看这个效果:
    Option ExplicitPrivate Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
         ByVal hwnd As Long, _
         ByVal nIndex As Long) As LongPrivate Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
         ByVal hwnd As Long, _
         ByVal nIndex As Long, _
         ByVal dwNewLong As Long) As LongPrivate Declare Function SetLayeredWindowAttributes Lib "user32.dll" ( _
         ByVal hwnd As Long, _
         ByVal crKey As Long, _
         ByVal bAlpha As Byte, _
         ByVal dwFlags As Long) As Long
         
    'Constant
    Private Const LWA_ALPHA As Long = &H2
    Private Const GWL_EXSTYLE As Long = (-20)
    Private Const WS_EX_LAYERED As Long = &H80000
    Public Function TransparentWindow(Frmhwnd As Long, AlphaValue As Long) As Long
        Dim Retrieved As Long
        
        Retrieved = GetWindowLong(Frmhwnd, GWL_EXSTYLE)
        
        Retrieved = Retrieved Or WS_EX_LAYERED
        
        SetWindowLong Frmhwnd, GWL_EXSTYLE, Retrieved
        
        SetLayeredWindowAttributes Frmhwnd, 0&, AlphaValue, LWA_ALPHA
        
        
    End Function
    Private Sub Command1_Click()
        TransparentWindow Me.hwnd, 150&
        
    End Sub
      

  7.   

    SetLayeredWindowAttributes Frmhwnd, 0&, AlphaValue, LWA_ALPHA有问题,找不到DLL的入口处
      

  8.   

    看看这个Public Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As LongPublic Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As LongPublic Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As LongPublic Const RGN_XOR = 3Public Type POINTAPI
            x As Long
            y As Long
    End Type窗体的BorderStyele属性为0
    ScaleMode为3Private Sub Command1_Click()
    Dim rect(4) As POINTAPI
    Dim lrgn As Long
    Dim temprgn As Longlrgn = CreateRectRgn(Command1.Left, Command1.Top, Command1.Left + Command1.Width, Command1.Top + Command1.Height)temprgn = CreateRectRgn(Command2.Left, Command2.Top, Command2.Left + Command2.Width, Command2.Top + Command2.Height)CombineRgn lrgn, lrgn, temprgn, RGN_XORSetWindowRgn Me.hWnd, lrgn, True
    End Sub
      

  9.   

    透明?
    用alphablend最简单
    桌面的DC用getdc(0)获得