使用VB6的半透明表格

时间:2010-09-01 18:39:30

标签: vb6

是否可以创建一个半透明的表单,它应该在任何打开的窗口上可见,而不是隐藏在后面?请指导!

2 个答案:

答案 0 :(得分:4)

当然,请参阅Karl Peterson的“半透明”示例:http://vb.mvps.org/samples/Translucent/

要使表单在其他窗口中可见,您需要使用SetWindowPos API函数。

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

Private Const HWND_TOPMOST = -1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const OnTopFlags = SWP_NOMOVE Or SWP_NOSIZE

Public Sub FormOnTop(frm As Form)
    Call SetWindowPos(frm.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, OnTopFlags)
End Sub

答案 1 :(得分:1)

'function to make transparent'

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 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 Const G = (-20)
Private Const LWA_COLORKEY = &H1        'to trans'
Private Const LWA_ALPHA = &H2           'to semi trans'
Private Const WS_EX_LAYERED = &H80000

Private Sub Form_Activate()
    Me.BackColor = vbBlue
    Trans 1
End Sub

Private Sub Trans(Level As Integer)
    Dim Msg As Long
    Msg = GetWindowLong(Me.hwnd, G)
    Msg = Msg Or WS_EX_LAYERED
    SetWindowLong Me.hwnd, G, Msg
    SetLayeredWindowAttributes Me.hwnd, vbBlue, Level, LWA_COLORKEY
End Sub
相关问题