说实在的我不知道这所谓透明的Form用在什麽地方,它变成透明後,只要有所移动,
或Mouse移到TitleBae处时,结果总是令人感到莫名奇妙,所以我设定BorderStyle = 0
,令之没有TitleBar。网路上见许多人问起,故有这程式;若有人知道这是用在何处,
请告诉我。
後来我在一个不小心,发现另一种作法令Form变透明的方式,而且比目前的作法好用
请叁考透明的Form上显示背景透通图
可以用SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT)来完成
'form上有Command1, command2两个Button并事先设定form之BorderStyle = 0
Option Explicit
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
Const GWL_EXSTYLE = (-20)
Const WS_EX_TRANSPARENT = &H20&
Private PreValue As Long
Private Sub Command2_Click() '还原变成不透明
Call SetWindowLong(Me.hwnd, GWL_EXSTYLE, PreValue)
Me.Hide
Me.Show
End Sub
Private Sub Form_Load()
Dim i As Long
i = GetWindowLong(Me.hwnd, GWL_EXSTYLE)
'变成透明的Form
PreValue = SetWindowLong(Me.hwnd, GWL_EXSTYLE, i Or WS_EX_TRANSPARENT)
Me.Show
DoEvents
Command1.Refresh '令Command1可见
Command2.Refresh '令Command2可见
End Sub
