|
hitosi さん、こんにちわ。
>ユーザーフォーム全体を半透明にすることってできますか?
フォームにスクロールバー(ScrollBar1)を配置し、以下を全てユーザーフォームのコードに記述。
Option Explicit
'API宣言
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" (ByVal wnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlag 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 Declare Function GetActiveWindow Lib "user32" () As Long
'
Const WS_EX_LAYERED = &H80000
Const LWA_ALPHA = 2
Const GWL_EXSTYLE = -20 'GWL_EXSTYLE
'
Private hLibUser32 As Long
Dim hwnd As Long, tr As Byte
'
Public Function xGetActiveWindow() As Long
xGetActiveWindow = GetActiveWindow
End Function
'
Private Sub ScrollBar1_Change()
tr = CByte(ScrollBar1.Value)
Call SetLayeredWindowAttributes(hwnd, 0, tr, LWA_ALPHA)
UserForm1.Caption = "透明度: " & Format(1 - (ScrollBar1.Value / 255), "0%")
End Sub
Private Sub UserForm_Activate()
Dim p As Long
hwnd = xGetActiveWindow
Call SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
'スクロールバーの設定
With ScrollBar1
.Max = 255
.Min = 20 '消えすぎると見失うのでこの程度まで
.Value = 127 '50%
End With
End Sub
|
|