#include "Form.ab"

Namespace ActiveBasic
Namespace Windows
Namespace UI

Class Dialog
	Inherits Form
Public

	Override Function DefWndProc(m As DWord, w As WPARAM, l As LPARAM) As LRESULT
		DefWndProc = FALSE
	End Function

	Function DoModal(hwndParent As HWND) As Long
		Dim temp[31] As Byte
		SetWord(temp + 0, 1) '拡張テンプレート
		SetWord(temp + 2, &hffff)
		SetDWord(temp + 12, DS_MODALFRAME Or WS_SYSMENU)
		StartWndProc()
		DoModal = DialogBoxIndirectParam(Control.hInstance, temp As *DLGTEMPLATE, hwndParent, AddressOf(DefDlgProc), 0)
	End Function

Private
	Static Function DefDlgProc(hDlg As HWND, msg As DWord, wp As WPARAM, lp As LPARAM) As LONG_PTR
		Dim lr = Control.WndProcFirst(hDlg, msg, wp, lp)
		If lr <> 0 Then
			Select Case msg
				Case WM_CHARTOITEM, _
					WM_COMPAREITEM, _
					WM_CTLCOLORBTN, _
					WM_CTLCOLORDLG, _
					WM_CTLCOLOREDIT, _
					WM_CTLCOLORLISTBOX, _
					WM_CTLCOLORSCROLLBAR, _
					WM_CTLCOLORSTATIC, _
					WM_INITDIALOG, _
					WM_QUERYDRAGICON, _
					WM_VKEYTOITEM
	
					DefDlgProc = lr
				Case Else
					_System_SetWindowLongPtr(hDlg, DWLP_MSGRESULT, lr)
			End Select
		End If
	End Function

End Class

End Namespace
End Namespace
End Namespace
