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 Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA
End Sub
这个窗口虽然透明了,但上面的控件也透明。想想办法吧
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 0, 200, LWA_ALPHA
End Sub
这个窗口虽然透明了,但上面的控件也透明。想想办法吧
不知成不成教一下啦!!
半透明的不知道办法,我的代码可以窗体全透明,而控件可见
Option Explicit
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, _
ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
ByVal hObject As Long) As LongPrivate Sub Form_Load()
Dim Bitmap
Me.AutoRedraw = True
Bitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, Bitmap '设置窗体透明
End Sub
Dim w As Single, h As Single
Dim edge As Single, topEdge As Single
Dim mLeft, mTop
Dim i As Integer
Dim R As Long
Dim outer As Long, inner As Long
mFormRegion = CreateRectRgn(0, 0, 0, 0)
w = ScaleX(Width, vbTwips, vbPixels)
h = ScaleY(Height, vbTwips, vbPixels)
edge = (w - ScaleWidth) / 2
topEdge = h - edge - ScaleHeight
If inFlag Then
outer = CreateRectRgn(0, 0, w, h)
inner = CreateRectRgn(edge, topEdge, w - edge, h - edge)
CombineRgn mFormRegion, outer, inner, RGN_DIFF
End If
For i = 0 To Me.Controls.Count - 1
mLeft = ScaleX(Me.Controls(i).Left, Me.ScaleMode, vbPixels) + edge
mTop = ScaleX(Me.Controls(i).Top, Me.ScaleMode, vbPixels) + topEdge
R = CreateRectRgn(mLeft, mTop, _
ScaleX((Me.Controls(i).Width), Me.ScaleMode, vbPixels) + mLeft, _
ScaleY((Me.Controls(i).Height), Me.ScaleMode, vbPixels) + mTop)
CombineRgn mFormRegion, R, mFormRegion, RGN_OR
Next
SetWindowRgn hwnd, mFormRegion, True
End Sub这是透明的过程。
在窗体的risize里调用。
Private Sub Form_Resize()
withFrameFlag = True
toggleFrame withFrameFlag
End Sub
少API申明啊什么的,自己搜索吧。