Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetWindowLong Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
// 반투명효과를 주는 API함수(Windows2000이상에서만 가능하다)
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal
hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal
dwFlags As Long) As Long
//
API 함수를 위한 상수
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_COLORKEY = &H1
Private Const LWA_ALPHA = &H2
Private Const GWL_EXSTYLE = (-20)
Private hwnd As Long
Private Sub HScroll1_Change()
Dim lngAlpha As Long
Me.Caption = "투명도:" & CStr(HScroll1.Value) & "%"
// 투명도(0~255)를 0~100으로 환산
lngAlpha = 255 - (255 * (HScroll1.Value / 100))
// 위의 알파값으로 투명도 함수 호출
Call SetLayeredWindowAttributes(hwnd, RGB(0, 0, 255), lngAlpha,
LWA_ALPHA)
End
Sub
Private Sub UserForm_Initialize()
Dim nIndex As Long
If Val(Application.Version) < 9 Then
hwnd = FindWindow("ThunderXFrame", Me.Caption) //
XL97이하 Else
hwnd = FindWindow("ThunderDFrame", Me.Caption) //
XL2000이상
End If
// 윈도우의 스타일을 구한다
nIndex = GetWindowLong(hwnd, GWL_EXSTYLE)
// 윈도우의 스타일을 레이어드 윈도우로 변경한다
Call SetWindowLong(hwnd, GWL_EXSTYLE, nIndex Or WS_EX_LAYERED)
// 윈도우의 투명도를 지정한다
Call HScroll1_Change
End Sub |