Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/Control.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/Control.ab	(revision 542)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/Control.ab	(revision 544)
@@ -14,7 +14,4 @@
 Class Control
 Public
-
-'1
-
 	Sub Control()
 	End Sub
@@ -47,5 +44,5 @@
 
 '--------------------------------
-' 1 ウィンドウ作成
+' ウィンドウ作成
 /*
 	Function Create(
@@ -90,22 +87,4 @@
 Public
 	Virtual Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
-/*
-		Select Case msg
-			Case WM_MOUSELEAVE
-				OnMouseLeave(makeMouseEventFromWPLP(wp, lp))
-				mouseEntered = False
-			Case WM_KEYDOWN
-				OnKeyDown(New KeyEventArgs(makeKeysFormWPLP(wp, lp)))
-			Case WM_KEYUP
-				OnKeyUp(New KeyEventArgs(makeKeysFormWPLP(wp, lp)))
-			Case WM_CHAR
-				OnKeyPress(New KeyPressEventArgs(wp As Char))
-'			Case WM_CREATE
-			Case WM_DESTROY
-				OnDestroy(EventArgs.Empty)
-			Case Else
-				WndProc = DefWndProc(msg, wp, lp)
-		End Select
-*/
 		Dim h = Nothing As MessageEventHandler
 		Dim b = messageMap.TryGetValue(Hex$(msg), h)
@@ -126,15 +105,17 @@
 
 Private
-	Static Function makeKeysFormWPLP(wp As WPARAM, lp As LPARAM) As Keys
+	Static Function makeKeysFormMsg(e As MessageEventArgs) As Keys
 		Dim t As DWord
-		t = wp And Keys.KeyCode
+		t = e.WParam And Keys.KeyCode
 		t Or= (GetKeyState(VK_SHIFT) As Word And &h8000) << 1
 		t Or= (GetKeyState(VK_CONTROL) As Word And &h8000) << 2
 		t Or= (GetKeyState(VK_MENU) As Word And &h8000) << 3
-		makeKeysFormWPLP = t As Keys
-	End Function
-
-	Static Function makeMouseEventFromWPLP(wp As WPARAM, lp As LPARAM) As MouseEventArgs
-		makeMouseEventFromWPLP = New MouseEventArgs(LOWORD(wp) As MouseButtons, 1, GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 0)
+		makeKeysFormMsg = t As Keys
+	End Function
+
+	Static Function makeMouseEventFromMsg(e As MessageEventArgs) As MouseEventArgs
+		Dim wp = e.WParam
+		Dim lp = e.LParam
+		makeMouseEventFromMsg = New MouseEventArgs(LOWORD(wp) As MouseButtons, 1, GET_X_LPARAM(lp), GET_Y_LPARAM(lp), 0)
 	End Function
 
@@ -146,5 +127,4 @@
 	Sub StartWndProc()
 		Dim t = This '#177対策
-		messageMap = New System.Collections.Generic.Dictionary<Object, MessageEventHandler>
 		AddMessageEvent(WM_ERASEBKGND, AddressOf(t.OnEraseBackground))
 		Dim md = New MessageEventHandler(AddressOf(t.OnMouseDownBase))
@@ -163,5 +143,10 @@
 		AddMessageEvent(WM_MBUTTONDBLCLK, mu)
 		AddMessageEvent(WM_XBUTTONDBLCLK, mu)
+
+		AddMessageEvent(WM_MOUSELEAVE, AddressOf(t.OnMouseLeaveBase))
 		AddMessageEvent(WM_PAINT, AddressOf(t.OnPaintBase))
+		AddMessageEvent(WM_KEYDOWN, AddressOf(t.OnKeyDownBase))
+'		AddMessageEvent(WM_CHAR, AddressOf(t.OnChar))	
+		AddMessageEvent(WM_CREATE, AddressOf(t.OnCreateBase))
 	End Sub
 
@@ -174,11 +159,11 @@
 
 	Sub OnMouseDownBase(sender As Object, e As MessageEventArgs)
-		OnMouseDown(makeMouseEventFromWPLP(e.WParam, e.LParam))
+		OnMouseDown(makeMouseEventFromMsg(e))
 	End Sub
 
 	Sub OnMouseUpBase(sender As Object, e As MessageEventArgs)
-		Dim me = makeMouseEventFromWPLP(e.WParam, e.LParam)
+		Dim me = makeMouseEventFromMsg(e)
 		If doubleClickFired = False Then
-			OnClick(EventArgs.Empty)
+'			OnClick(System.EventArgs.Empty)
 			OnMouseClick(me)
 			doubleClickFired = False
@@ -188,13 +173,13 @@
 
 	Sub OnMouseDblClkBase(sender As Object, e As MessageEventArgs)
-		Dim me = makeMouseEventFromWPLP(e.WParam, e.LParam)
+		Dim me = makeMouseEventFromMsg(e)
 		doubleClickFired = True
 		OnMouseDown(me)
-		OnDoubleClick(EventArgs.Empty)
+'		OnDoubleClick(System.EventArgs.Empty)
 		OnMouseDoubleClick(me)
 	End Sub
 
 	Sub OnMouseMoveBase(sender As Object, e As MessageEventArgs)
-		Dim me = makeMouseEventFromWPLP(e.WParam, e.LParam)
+		Dim me = makeMouseEventFromMsg(e)
 		If mouseEntered Then
 			OnMouseMove(me)
@@ -205,14 +190,36 @@
 	End Sub
 
+	Sub OnMouseLeaveBase(sender As Object, e As MessageEventArgs)
+		Dim me = makeMouseEventFromMsg(e)
+		OnMouseLeave(me)
+		mouseEntered = False
+	End Sub
+
 	Sub OnPaintBase(sender As Object, e As MessageEventArgs)
 		Dim ps As PAINTSTRUCT
 		BeginPaint(hwnd, ps)
-'		Try
-'			OnPaintDC(New PaintDCEventArgs(ps.hdc, ps.rcPaint))
-'		Finally
+		Try
+			OnPaintDC(New PaintDCEventArgs(ps.hdc, ps.rcPaint))
+		Finally
 			EndPaint(hwnd, ps)
-'		End Try
-	End Sub
-
+		End Try
+	End Sub
+
+	Sub OnKeyDownBase(sender As Object, e As MessageEventArgs)
+		OnKeyDown(New KeyEventArgs(makeKeysFormMsg(e)))
+	End Sub
+
+	Sub OnKeyUpBase(sender As Object, e As MessageEventArgs)
+		OnKeyUp(New KeyEventArgs(makeKeysFormMsg(e)))
+	End Sub
+
+'	コメントアウト解除のときはStartWndProcのコメントアウト解除も忘れないこと
+'	Sub OnChar(sender As Object, e As MessageEventArgs)
+'		OnKeyPress(New KeyPressEventArgs(e.WParam As Char))
+'	End Sub
+
+	Sub OnCreateBase(sender As Object, e As MessageEventArgs)
+		OnCreate(New CreateEventArgs(e.LParam As *CREATESTRUCT))
+	End Sub
 
 	messageMap As System.Collections.Generic.Dictionary<Object /*DWord*/, MessageEventHandler>
@@ -260,10 +267,9 @@
 '--------
 'イベント
-' 3
 
 #include "ControlEvent.sbp"
 
 '--------------------------------
-' 1 インスタンスメンバ変数
+' インスタンスメンバ変数
 Private
 	hwnd As HWND
@@ -281,5 +287,5 @@
 
 '--------------------------------
-' 1 初期ウィンドウクラス
+' 初期ウィンドウクラス
 Private
 	Static Function WndProcFirst(hwnd As HWND, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
@@ -339,5 +345,5 @@
 
 '--------------------------------
-' 1 初期化終了関連（特にウィンドウクラス）
+' 初期化終了関連（特にウィンドウクラス）
 Private
 	'ウィンドウ作成時にウィンドウプロシージャへThisを伝えるためのもの
@@ -450,13 +456,23 @@
 	Inherits Form
 Public
-	Sub NcDestory(sender As Object, et As EventArgs)
+	Sub t()
+		Dim f = This
+		f.AddMessageEvent(WM_DESTROY, AddressOf (f.Destory))
+		f.AddPaintDC(AddressOf (f.Paint))
+	End Sub
+
+	Sub Destory(sender As Object, e As EventArgs)
+		OutputDebugString(Ex"Destory\r\n")
 		PostQuitMessage(0)
 	End Sub
+
+	Sub Paint(sender As Object, e As PaintDCEventArgs)
+		TextOut(e.Handle, 10, 10, "Hello world!", 12)
+	End Sub
 End Class
 
 Dim f = New MyForm
+f.t()
 f.Create()
-Dim h = New MessageEventHandler(AddressOf (f.NcDestory))
-f.AddMessageEvent(WM_NCDESTROY, h)
 ShowWindow(f.Handle, SW_SHOW)
 
@@ -481,3 +497,2 @@
 
 End
-
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEvent.sbp
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEvent.sbp	(revision 542)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEvent.sbp	(revision 544)
@@ -1,3 +1,2 @@
-
 Public
 	Sub AddPaintDC(h As PaintDCEventHandler)
@@ -23,48 +22,4 @@
 
 Public
-	Sub AddClick(h As System.EventHandler)
-		If IsNothing(click) Then
-			click = h
-		Else
-			click += h
-		End If
-	End Sub
-	Sub RemoveClick(h As System.EventHandler)
-		If Not IsNothing(click) Then
-			click -= h
-		End If
-	End Sub
-Private
-	Sub OnClick(e As System.EventArgs)
-		If Not IsNothing(click) Then
-			click(This, e)
-		End If
-	End Sub
-Private
-	click As System.EventHandler
-
-Public
-	Sub AddDoubleClick(h As System.EventHandler)
-		If IsNothing(doubleClick) Then
-			doubleClick = h
-		Else
-			doubleClick += h
-		End If
-	End Sub
-	Sub RemoveDoubleClick(h As System.EventHandler)
-		If Not IsNothing(doubleClick) Then
-			doubleClick -= h
-		End If
-	End Sub
-Private
-	Sub OnDoubleClick(e As System.EventArgs)
-		If Not IsNothing(doubleClick) Then
-			doubleClick(This, e)
-		End If
-	End Sub
-Private
-	doubleClick As System.EventHandler
-
-Public
 	Sub AddMouseEnter(h As MouseEventHandler)
 		If IsNothing(mouseEnter) Then
@@ -285,26 +240,4 @@
 Private
 	keyUp As KeyEventHandler
-/*
-Public
-	Sub AddKeyPress(h As KeyPressEventHandler)
-		If IsNothing(keyPress) Then
-			keyPress = h
-		Else
-			keyPress += h
-		End If
-	End Sub
-	Sub RemoveKeyPress(h As KeyPressEventHandler)
-		If Not IsNothing(keyPress) Then
-			keyPress -= h
-		End If
-	End Sub
-Private
-	Sub OnKeyPress(e As KeyPressEventArgs)
-		If Not IsNothing(keyPress) Then
-			keyPress(This, e)
-		End If
-	End Sub
-Private
-	keyPress As KeyPressEventHandler
 
 Public
@@ -329,3 +262,3 @@
 Private
 	create As CreateEventHandler
-*/
+
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEventList.txt
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEventList.txt	(revision 542)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/ControlEventList.txt	(revision 544)
@@ -1,5 +1,5 @@
 PaintDC	PaintDCEvent	ウィンドウの描画が必要なときに呼び出されます。
-Click	Event	クリックされたときに呼び出されます。
-DoubleClick	Event	ダブルクリックされたときに呼び出されます。
+'Click	Event	クリックされたときに呼び出されます。
+'DoubleClick	Event	ダブルクリックされたときに呼び出されます。
 'EnableChanged	Event	有効状態が変化したときに呼び出されます。
 'Move	Event	ウィンドウが移動したときに呼び出されます。
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/EventArgs.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/EventArgs.ab	(revision 542)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Forms/EventArgs.ab	(revision 544)
@@ -491,4 +491,24 @@
 Delegate Sub CreateEventHandler(sender As Object, e As CreateEventArgs)
 
+Class FormClosingEventArgs
+	Inherits EventArgs
+Public
+	Sub FormClosingEventArgs()
+		c = False
+	End Sub
+
+	Function Cancel() As Boolean
+		Cancel = c
+	End Function
+
+	Sub Cancel(cancel As Boolean)
+		c = cancel
+	End Sub
+Private
+	c As Boolean
+End Class
+
+Delegate Sub FormClosingEventHandler(sender As Object, e As FormClosingEventArgs)
+
 End Namespace 'Forms
 End Namespace 'UI
