声明:
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)
透明效果是出来啦,如果移动的话,屏幕会变乱。这是我在网上看到的,还没有试过,有兴趣试试!
呵呵……
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)
透明效果是出来啦,如果移动的话,屏幕会变乱。这是我在网上看到的,还没有试过,有兴趣试试!
呵呵……
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
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
这些方法都不好?
我想用CombinRgn和SetWindowLong的效果会更好一些。
合并区域时用RGN_XOR参数,可以达到该效果。
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
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
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
用alphablend最简单
桌面的DC用getdc(0)获得