Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Button.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Button.ab	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Button.ab	(revision 637)
@@ -13,5 +13,5 @@
 */
 Class Button
-	Inherits Control
+	Inherits WmCommandControl
 Protected
 	Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
@@ -26,4 +26,20 @@
 	End Sub
 
+	Override Function RaiseCommandEvent(notificationCode As Word) As Boolean
+		Dim lr As LRESULT
+		RaiseCommandEvent = False
+		Select Case notificationCode
+			Case BN_CLICKED
+				RaiseCommandEvent = OnClick(Args.Empty)
+			Case BN_DBLCLK
+				RaiseCommandEvent = OnDoubleClick(Args.Empty)
+			Case BN_SETFOCUS
+				RaiseCommandEvent = ProcessMessage(WM_SETFOCUS, 0, 0, lr)
+			Case BN_KILLFOCUS
+				RaiseCommandEvent = ProcessMessage(WM_KILLFOCUS, 0, 0, lr)
+			'ここに挙げられなかったBNメッセージは、16ビットWindowsとの互換性のためとされているもの。
+		End Select
+	End Function
+
 End Class
 
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab	(revision 637)
@@ -138,4 +138,8 @@
 		registerStandardEvent()
 		AssociateHWnd(hwndNew)
+	End Sub
+
+	Sub BeginSubclass()
+		throwIfNotCreated()
 		prevWndProc = SetWindowLongPtr(GWLP_WNDPROC, AddressOf(WndProcFirst) As LONG_PTR) As WNDPROC
 	End Sub
@@ -144,5 +148,11 @@
 	Sub throwIfAlreadyCreated()
 		If hwnd <> 0 Then
-			Throw New System.InvalidOperationException("Window already created.")
+			Throw New System.InvalidOperationException("Window is already created.")
+		End If
+	End Sub
+
+	Sub throwIfNotCreated()
+		If hwnd = 0 Then
+			Throw New System.InvalidOperationException("Window is not already created.")
 		End If
 	End Sub
@@ -150,7 +160,21 @@
 '--------------------------------
 ' ウィンドウプロシージャ
-'Protected
-Public
+
+Protected
 	Virtual Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
+		If Not ProcessMessage(msg, wp, lp, WndProc) Then
+			WndProc = DefWndProc(msg, wp, lp)
+		End If
+	End Function
+
+	Virtual Function DefWndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
+		If prevWndProc Then
+			DefWndProc = CallWindowProc(prevWndProc, hwnd, msg, wp, lp)
+		Else
+			DefWndProc = DefWindowProc(hwnd, msg, wp, lp)
+		End If
+	End Function
+Protected
+	Function ProcessMessage(msg As DWord, wp As WPARAM, lp As LPARAM, ByRef lr As LRESULT) As Boolean
 		Dim h = Nothing As MessageHandler
 		Dim b = messageMap.TryGetValue(Hex$(msg), h)
@@ -160,20 +184,12 @@
 				h(This, a)
 				If a.Handled Then
-					WndProc = a.LResult
+					lr = a.LResult
+					ProcessMessage = True
 					Exit Function
 				End If
 			End If
 		End If
-		WndProc = DefWndProc(msg, wp, lp)
-	End Function
-
-	Virtual Function DefWndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
-		If prevWndProc Then
-			DefWndProc = CallWindowProc(prevWndProc, hwnd, msg, wp, lp)
-		Else
-			DefWndProc = DefWindowProc(hwnd, msg, wp, lp)
-		End If
-	End Function
-
+		ProcessMessage = False
+	End Function
 Private
 	Static Function makeKeysFormMsg(e As MessageArgs) As Keys
@@ -428,5 +444,5 @@
 	*/
 	Sub AssociateHWnd(hwndNew As HWND)
-		hwnd = hwndNew
+		SetHWnd(hwndNew)
 		Prop[PropertyInstance] = ObjPtr(This) As HANDLE
 		comImpl.AddRef()
@@ -513,4 +529,7 @@
 	Static Sub Initialize(hinst As HINSTANCE)
 		tlsIndex = TlsAlloc()
+		If tlsIndex = TLS_OUT_OF_INDEXES Then
+			ThrowWithLastError("Control.Initialize: TlsAlloc failed.")
+		End If
 		hInstance = hinst
 		hmodComctl = LoadLibrary("comctl32.dll")
@@ -519,4 +538,7 @@
 		Dim PropertyInstanceString = WindowClassName + " " + Hex$(GetCurrentProcessId())
 		PropertyInstance = GlobalAddAtom(ToTCStr(PropertyInstanceString))
+		If PropertyInstance = 0 Then
+			ThrowWithLastError("Control.Initialize: GlobalAddAtom failed.")
+		End If
 
 		Dim wcx As WNDCLASSEX
@@ -537,9 +559,5 @@
 		atom = RegisterClassEx(wcx)
 		If atom = 0 Then
-			Dim buf[1023] As TCHAR
-			wsprintf(buf, Ex"ActiveBasic.Windows.UI.Control.Control: RegisterClasseEx failed. Error code: &h%08X\r\n", GetLastError())
-			OutputDebugString(buf)
-			Debug
-			ExitThread(0)
+			ThrowWithLastErrorNT("Control.Initialize: RegisterClasseEx failed.")
 		End If
 	End Sub
@@ -561,4 +579,17 @@
 End Class
 
+/*!
+@brief WM_COMMANDで通知を行うコントロールの基底クラス
+@date 2008/08/28
+@auther Egtra
+親がWM_COMMANDを受け取ったら、RaiseCommandEventを呼ぶことを意図している。
+（Formで実装済み）
+*/
+Class WmCommandControl
+	Inherits Control
+Public
+	Abstract Function RaiseCommandEvent(notificationCode As Word) As Boolean
+End Class
+
 End Namespace 'UI
 End Namespace 'Widnows
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Dialog.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Dialog.ab	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Dialog.ab	(revision 637)
@@ -8,9 +8,4 @@
 	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
@@ -20,4 +15,8 @@
 		StartWndProc()
 		DoModal = DialogBoxIndirectParam(Control.hInstance, temp As *DLGTEMPLATE, hwndParent, AddressOf(DefDlgProc), 0)
+	End Function
+Protected
+	Override Function DefWndProc(m As DWord, w As WPARAM, l As LPARAM) As LRESULT
+		DefWndProc = FALSE
 	End Function
 
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/EditBox.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/EditBox.ab	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/EditBox.ab	(revision 637)
@@ -8,9 +8,9 @@
 /*!
 @brief エディトコントロールのクラス
-@date 2007/07/21
+@date 2008/07/21
 @auther Egtra
 */
 Class EditBox
-	Inherits Control
+	Inherits WmCommandControl
 Protected
 	Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
@@ -19,4 +19,8 @@
 		End With
 	End Sub
+Public
+	Override Function RaiseCommandEvent(notificationCode As Word) As Boolean
+		RaiseCommandEvent = False
+	End Function
 
 	'ToDo: Lineなどを設ける
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Form.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Form.ab	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Form.ab	(revision 637)
@@ -39,12 +39,11 @@
 
 	Sub OnCommand(sender As Object, e As MessageArgs)
-		Dim id = e.WParam And &hffff 'LOWORD(e.WParam)
-		Dim cmd = (e.WParam >> 16) And &hffff 'HIWORD(e.WParam)
+'		Dim id = e.WParam And &hffff 'LOWORD(e.WParam)
+		Dim cmd = ((e.WParam >> 16) And &hffff) As Word 'HIWORD(e.WParam)
 		Dim hwnd = e.LParam As HWND
-		If cmd = BN_CLICKED And hwnd <> 0 Then
-			Dim c = Control.FromHWnd(hwnd)
+		If hwnd <> 0 Then
+			Dim c = Control.FromHWnd(hwnd) As WmCommandControl
 			If IsNothing(c) = False Then
-				Dim b = c As Button
-				b.RaiseClick()
+				c.RaiseCommandEvent(cmd)
 			End If
 		End If
Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/WindowHandle.sbp
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/WindowHandle.sbp	(revision 620)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/WindowHandle.sbp	(revision 637)
@@ -308,13 +308,9 @@
 	End Function
 */
-	Function Move(x As Long, y As Long, width As Long, height As Long, repaint As Boolean) As Boolean
+	Function Move(x As Long, y As Long, width As Long, height As Long, repaint = True As Boolean) As Boolean
 		Return MoveWindow(hwnd, x, y, width, height, repaint) As Boolean
 	End Function
 
-	Function Move(x As Long, y As Long, width As Long, height As Long) As Boolean
-		Return MoveWindow(hwnd, x, y, width, height, TRUE) As Boolean
-	End Function
-
-	Function Move(ByRef rc As RECT, repaint As Boolean) As Boolean
+	Function Move(ByRef rc As RECT, repaint = True As Boolean) As Boolean
 		With rc
 			Return MoveWindow(hwnd, .left, .top, .right - .left, .bottom - .top, repaint) As Boolean
@@ -322,9 +318,4 @@
 	End Function
 
-	Function Move(ByRef rc As RECT) As Boolean
-		With rc
-			Return MoveWindow(hwnd, .left, .top, .right - .left, .bottom - .top, TRUE) As Boolean
-		End With
-	End Function
 /*
 	Function OpenClipboard() As Boolean
@@ -586,5 +577,5 @@
 
 	Const Function Maximized() As Boolean
-		Return IsIconic() As Boolean
+		Return IsZoomed(hwnd) As Boolean
 	End Function
 
@@ -668,4 +659,5 @@
 		sb.Length = size
 		Dim length = GetWindowText(hwnd, StrPtr(sb), size)
+		sb.Length(length)
 		Text = sb.ToString
 	End Function
