Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" _
(ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Long, ByVal dwFlags As Long) As Long
Private Const LWA_COLORKEY = 1
Private Const LWA_ALPHA = 2
Private Const WS_EX_LAYERED = &H80000
Private Sub Command1_Click()
Dim dwStyle As Long
dwStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
dwStyle = dwStyle Or WS_EX_LAYERED
Call SetWindowLong(Me.hWnd, GWL_EXSTYLE, dwStyle)
Call SetLayeredWindowAttributes(Me.hWnd, 0, 150, LWA_ALPHA)
End Sub
Private Sub Command2_Click()
Dim dwStyle As Long
dwStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
dwStyle = dwStyle Or WS_EX_LAYERED
Call SetWindowLong(Me.hWnd, GWL_EXSTYLE, dwStyle)
Call SetLayeredWindowAttributes(Me.hWnd, Me.Frame1.BackColor, 150, LWA_COLORKEY)
End Sub
Private Sub Form_Load()
Me.Label1.Caption = "透明なウィンドウを作成する" & vbCrLf & _
"(256以下では透明なウィンドウは作成されません)"
End Sub |