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 hBitmap As Long Me.AutoRedraw = True hBitmap = CreateCompatibleBitmap(Me.hdc, 0, 0) SelectObject Me.hdc, hBitmap Me.Refresh End Sub
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 crey As Byte, _ ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Private Const GWL_EXSTYLE = (-20) Private Const WS_EX_LAYERED = &H80000 Private Const LWA_ALPHA = &H2&Private Sub Command1_Click() Dim bytOpacity As Byte 'Set the transparency level bytOpacity = 128 Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, _ GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED) Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, _ LWA_ALPHA) End SubPrivate Sub Command2_Click() Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, _ GetWindowLong(Me.hwnd, GWL_EXSTYLE) _ And (Not WS_EX_LAYERED)) End Sub这是Win32 Api的代码,不过98不支持............. 你要想在98里达到此效果 客户端必须装.net framework 用.net程序实现 或directx9 api
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) Private Sub Form_Load() retval = SetWindowLong(Form1.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT) End Sub
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 hBitmap As Long
Me.AutoRedraw = True
hBitmap = CreateCompatibleBitmap(Me.hdc, 0, 0)
SelectObject Me.hdc, hBitmap
Me.Refresh
End Sub
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 crey As Byte, _
ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2&Private Sub Command1_Click()
Dim bytOpacity As Byte
'Set the transparency level
bytOpacity = 128
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, _
GetWindowLong(Me.hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hwnd, 0, bytOpacity, _
LWA_ALPHA)
End SubPrivate Sub Command2_Click()
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, _
GetWindowLong(Me.hwnd, GWL_EXSTYLE) _
And (Not WS_EX_LAYERED))
End Sub这是Win32 Api的代码,不过98不支持.............
你要想在98里达到此效果
客户端必须装.net framework
用.net程序实现
或directx9 api
-------------------------
TO:楼上,你的连控件也是透明的了,有FAQ的:
http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=195426
try一下 ^_^
该设置有助于容器更快地绘制控件。如果没有选定此选项,则控件可以包含透明部分。
只有不透明的控件可以有纯色背景。"
Const WS_EX_TRANSPARENT = &H20&
Const GWL_EXSTYLE = (-20)
Private Sub Form_Load()
retval = SetWindowLong(Form1.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT)
End Sub
不信? 你可以按上面的诸位做出的透明窗体,打开, 然后你把壁纸修改了, 你会发现窗体后面的背景还是原来那样的?! 也就是说背景不会改变。
这是因为WIN9X的所有界面的实现效果其实就是一个BMP图形而已,你见过98下有透明的BMP图形吗?