Index: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab
===================================================================
--- trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab	(revision 545)
+++ trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/Control.ab	(revision 547)
@@ -12,5 +12,7 @@
 
 Class Control
+	Inherits WindowHandle
 Public
+
 	Sub Control()
 	End Sub
@@ -25,5 +27,5 @@
 	Static Function FromHWnd(hwnd As HWND) As Control
 		FromHWnd = Nothing
-		If IsWindow(hwnd) Then
+		If _System_IsWindow(hwnd) Then
 			FromHWnd = FromHWndCore(hwnd)
 		End If
@@ -32,5 +34,5 @@
 Private
 	Static Function FromHWndCore(hwnd As HWND) As Control
-		If GetClassLongPtr(hwnd, GCW_ATOM) = atom Then
+		If _System_GetClassLongPtr(hwnd, GCW_ATOM) = atom Then
 			Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR
 			If gchValue <> 0 Then
@@ -44,27 +46,25 @@
 '--------------------------------
 ' ウィンドウ作成
-/*
-	Function Create(
-		parent As HWND,
-		rect As RECT,
-		name As String,
-		style As DWord,
-		exStyle = 0 As DWord,
-		menu = 0 As HMENU) As HWND
-*/
+'	Function Create(
+'		parent As HWND,
+'		rect As RECT,
+'		name As String,
+'		style As DWord,
+'		exStyle = 0 As DWord,
+'		menu = 0 As HMENU) As HWND
 
 Public
-	Function Create() As Boolean
+	Sub Create()
 		Dim cs As CREATESTRUCT
 		cs.hInstance = hInstance
 		cs.lpszClass = (atom As ULONG_PTR) As LPCTSTR
 		GetCreateStruct(cs)
-		Create = createImpl(cs)
-	End Function
+		createImpl(cs)
+	End Sub
 
 Protected
 	Abstract Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
 
-	Function createImpl(ByRef cs As CREATESTRUCT) As Boolean
+	Sub createImpl(ByRef cs As CREATESTRUCT)
 		Imports System.Runtime.InteropServices
 
@@ -77,7 +77,9 @@
 			Dim hwnd = CreateWindowEx(.dwExStyle, .lpszClass, .lpszName, .style,
 				.x, .y, .cx, .cy, .hwndParent, .hMenu, .hInstance, .lpCreateParams)
-			createImpl = hwnd <> 0
+			If hwnd = 0 Then
+				ActiveBasic.Windows.ThrowByWindowsError(GetLastError())
+			End If
 		End With
-	End Function
+	End Sub
 
 '--------------------------------
@@ -125,17 +127,16 @@
 	*/
 	Sub StartWndProc()
-		Dim t = This '#177対策
-		AddMessageEvent(WM_ERASEBKGND, AddressOf(t.OnEraseBackground))
-		Dim md = New MessageEventHandler(AddressOf(t.OnMouseDownBase))
+		AddMessageEvent(WM_ERASEBKGND, AddressOf(OnEraseBackground))
+		Dim md = New MessageEventHandler(AddressOf(OnMouseDownBase))
 		AddMessageEvent(WM_LBUTTONDOWN, md)
 		AddMessageEvent(WM_RBUTTONDOWN, md)
 		AddMessageEvent(WM_MBUTTONDOWN, md)
 		AddMessageEvent(WM_XBUTTONDOWN, md)
-		Dim mu = New MessageEventHandler(AddressOf(t.OnMouseUpBase))
+		Dim mu = New MessageEventHandler(AddressOf(OnMouseUpBase))
 		AddMessageEvent(WM_LBUTTONUP, mu)
 		AddMessageEvent(WM_RBUTTONUP, mu)
 		AddMessageEvent(WM_MBUTTONUP, mu)
 		AddMessageEvent(WM_XBUTTONUP, mu)
-		Dim mb = New MessageEventHandler(AddressOf(t.OnMouseDblClkBase))
+		Dim mb = New MessageEventHandler(AddressOf(OnMouseDblClkBase))
 		AddMessageEvent(WM_LBUTTONDBLCLK, mu)
 		AddMessageEvent(WM_RBUTTONDBLCLK, mu)
@@ -143,14 +144,14 @@
 		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))
+		AddMessageEvent(WM_MOUSEMOVE, AddressOf(OnMouseMoveBase))
+		AddMessageEvent(WM_MOUSELEAVE, AddressOf(OnMouseLeaveBase))
+		AddMessageEvent(WM_PAINT, AddressOf(OnPaintBase))
+		AddMessageEvent(WM_KEYDOWN, AddressOf(OnKeyDownBase))
+'		AddMessageEvent(WM_CHAR, AddressOf(OnChar))	
+		AddMessageEvent(WM_CREATE, AddressOf(OnCreateBase))
 	End Sub
 
 	Sub OnEraseBackground(sender As Object, e As MessageEventArgs)
-		Dim rc As RECT
-		Dim r = GetClientRect(hwnd, rc)
+		Dim rc = ClientRect
 		FillRect(e.WParam As HDC, rc, (COLOR_3DFACE + 1) As HBRUSH)
 		e.LResult = TRUE
@@ -197,9 +198,9 @@
 	Sub OnPaintBase(sender As Object, e As MessageEventArgs)
 		Dim ps As PAINTSTRUCT
-		BeginPaint(hwnd, ps)
+		BeginPaint(ps)
 		Try
 			OnPaintDC(New PaintDCEventArgs(ps.hdc, ps.rcPaint))
 		Finally
-			EndPaint(hwnd, ps)
+			EndPaint(ps)
 		End Try
 	End Sub
@@ -272,5 +273,4 @@
 ' インスタンスメンバ変数
 Private
-	hwnd As HWND
 	/*!
 	@brief マウスカーソルがクライアント領域に入っているかどうかのフラグ
@@ -291,5 +291,5 @@
 		Imports System.Runtime.InteropServices
 
-		Dim rThis = Control.FromHWndCore(hwnd)
+		Dim rThis = FromHWndCore(hwnd)
 		If IsNothing(rThis) Then
 			Dim gchValue = TlsGetValue(tlsIndex) As LONG_PTR
@@ -306,12 +306,11 @@
 			End If
 			rThis.hwnd = hwnd
-			SetProp(hwnd, PropertyInstance As ULONG_PTR As PCSTR, gchValue As HANDLE)
+			rThis.Prop[PropertyInstance] = gchValue As HANDLE
 		End If
 		WndProcFirst = rThis.WndProc(msg, wp, lp)
 		If msg = WM_NCDESTROY Then
-			Dim gchValue = GetProp(hwnd, PropertyInstance As ULONG_PTR As PCTSTR) As ULONG_PTR
+			Dim gchValue = rThis.Prop(PropertyInstance) As ULONG_PTR
 			If gchValue <> 0 Then
-				Dim gch = GCHandle.FromIntPtr(gchValue)
-				gch.Free()
+				GCHandle.FromIntPtr(gchValue).Free()
 			End If
 		End If
@@ -320,5 +319,5 @@
 
 	*InstanceIsNotFound
-		OutputDebugString("ActiveBasic.Windows.UI.Control.WndProcFirst: The attached instance is not found.")
+		OutputDebugString(Ex"ActiveBasic.Windows.UI.Control.WndProcFirst: The attached instance is not found.\r\n")
 		WndProcFirst = DefWindowProc(hwnd, msg, wp, lp)
 	End Function
@@ -408,87 +407,5 @@
 End Class
 
-Class Form '仮
-	Inherits Control
-Protected
-	Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
-		With cs
-			.lpCreateParams = 0
-			'.hInstance
-			.hMenu = 0
-			.hwndParent = 0
-			.cy = CW_USEDEFAULT
-			.cx = CW_USEDEFAULT
-			.y = CW_USEDEFAULT
-			.x = CW_USEDEFAULT
-			.style = WS_OVERLAPPEDWINDOW
-			.lpszName = ""
-			'.lpszClass
-			.dwExStyle = 0
-		End With
-	End Sub
-Public 
-
-	Override Function WndProc(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
-		WndProc = 0
-		Select Case msg
-			Case Else
-				WndProc = Super.WndProc(msg, wp, lp)
-		End Select
-	End Function
-End Class
-
 End Namespace 'UI
 End Namespace 'Widnows
 End Namespace 'ActiveBasic
-
-'----------
-'テスト実行用
-
-Imports ActiveBasic.Windows.UI
-
-'OleInitialize()
-Control.Initialize(GetModuleHandle(0))
-
-Class MyForm
-	Inherits Form
-Public
-	Sub MyForm()
-		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.Create()
-ShowWindow(f.Handle, SW_SHOW)
-
-Dim m As MSG
-Do
-	Dim ret = GetMessage(m, 0, 0, 0)
-	If ret = 0 Then
-		Exit Do
-	ElseIf ret = -1 Then
-		ExitProcess(-1)
-	End If
-
-	TranslateMessage(m)
-	DispatchMessage(m)
-Loop
-
-f = Nothing
-System.GC.Collect()
-
-Control.Uninitialize()
-'OleUninitialize()
-
-End
