我如何在vb6.0中透明表单?

时间:2012-11-24 09:12:55

标签: vb6

  

可能重复:
  Semi Transparent Form using VB6

我想创建一个具有多个表单的vb应用程序,这些表单都是透明的,有一些文本。这可能吗?

1 个答案:

答案 0 :(得分:1)

如果您只想通过透明的表单来执行代码。

VB: 首先声明

Dim g_nTransparency As Integer
Public Const LWA_COLORKEY = 1
Public Const LWA_ALPHA = 2
Public Const LWA_BOTH = 3
Public Const WS_EX_LAYERED = &H80000
Public Const GWL_EXSTYLE = -20
Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal Color As Long, ByVal X As Byte, ByVal alpha As Long) As Boolean

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong 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 ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Sub SetTranslucent(ThehWnd As Long, nTrans As Integer)
'SetWindowLong and SetLayeredWindowAttributes are API functions, see MSDN for details
   Dim attrib As Long
   attrib = GetWindowLong(ThehWnd, GWL_EXSTYLE)
   SetWindowLong ThehWnd, GWL_EXSTYLE, attrib Or WS_EX_LAYERED
   SetLayeredWindowAttributes ThehWnd, RGB(255, 255, 0), nTrans, LWA_ALPHA    
End Sub

Public Function Transparent_Form()
  g_nTransparency = 190
  If g_nTransparency < 0 Then g_nTransparency = 0
  If g_nTransparency > 255 Then g_nTransparency = 255
  SetTranslucent Translucent.hwnd, g_nTransparency
  Translucent.Show
  mintCount = 0 
End Function