/*
レイヤードウィンドウを使用しているのでWindows 2000以上が必要。
チェックボックスの状態により透明度が変わるという例。
*/

#require <Classes/ActiveBasic/Windows/UI/Form.ab>
#require <Classes/ActiveBasic/Windows/UI/Application.ab>
#require <Classes/ActiveBasic/Windows/UI/CheckBox.ab>

#resource "UI_Sample.rc"

Imports ActiveBasic.Windows.UI

Const LWA_ALPHA = 2
Const WS_EX_LAYERED = &h00080000
Declare Function SetLayeredWindowAttributes Lib "user32" (hwnd As HWND, crKey As COLORREF, bAlpha As Byte, dwFlags As DWord) As BOOL

Class MyForm
	Inherits Form
Public
	Sub MyForm()
		CreateForm()

		Dim wpFont = GetStockObject(DEFAULT_GUI_FONT) As WPARAM

		checkBox = New CheckBox
		With checkBox
			.Create(This, 0, 0, 0)
			.Move(20, 20, 200, 20)
			.Text = "半透明化"
			.ThreeState = True
			.SendMessage(WM_SETFONT, wpFont, 0)
			.AddClick(AddressOf(OnClick))
		End With
		OnClick(This, Args.Empty)
		Show(SW_SHOWDEFAULT)
	End Sub
Protected
	Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
		Super.GetCreateStruct(cs)
		With cs
			.style = WS_CAPTION Or WS_BORDER Or WS_SYSMENU Or WS_DLGFRAME Or WS_MINIMIZEBOX
			.dwExStyle = WS_EX_LAYERED
			.cx = 320
			.cy = 240
		End With
	End Sub

Private
	Sub OnClick(sender As Object, e As Args)
		Dim alpha As Byte
		Dim state = checkBox.State
		Select Case state
			Case CheckState.Unchecked
				alpha = 255
			Case CheckState.Checked
				alpha = 200
			Case CheckState.Indeterminate
				alpha = 100
		End Select
		SetLayeredWindowAttributes(This, 0, alpha, LWA_ALPHA)
	End Sub

	checkBox As CheckBox
End Class

Control.Initialize(GetModuleHandle(0))

Dim f = New MyForm
Application.Run(f)
