.net或者其他平台下,透明窗体,一部分颜色透明的窗体,如Photoshop的启动窗体,可以很容易的制作。但VB 6不支持窗体透明或部分透明,需要制作透明窗体需要调用API函数。方法如下:
声明API:
Public Declare Function SetLayeredWindowAttributes Lib _
"user32" (ByVal hnd As Long, ByVal clval As Long, _
ByVal alph As Byte, ByVal flago As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Const LWA_ALPHA = &H2&
Public Const LWA_COLORKEY = &H1&
Public Const GWL_EXSTYLE = (-20)
Public Const WS_EX_LAYERED = &H80000
Public Const WS_EX_TRANSPARENT = &H20&
部分透明窗体(窗体的一部分颜色透明):
Dim lOldStyle As Long
lOldStyle = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
SetWindowLong Me.hwnd, GWL_EXSTYLE, lOldStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.hwnd, &HFFFFFF, 255, LWA_COLORKEY
整体半透明:
Dim lOldStyle As Long
Dim bTrans As Byte
bTrans = 200
lOldStyle = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
SetWindowLong Me.hwnd, GWL_EXSTYLE, lOldStyle Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.hwnd, COLOR_TRANSPARENCY, bTrans, LWA_COLORKEY
(其中COLOR_TRANSPARENCY是透明的颜色,使用16进制表示,如&H80000)