Index: trunk/Include/Classes/System/Windows/Forms/Control.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 388)
+++ trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 461)
@@ -1,25 +1,4 @@
 ' Classes/System/Windows/Forms/Control.ab
 
-#ifndef __SYSTEM_WINDOWS_FORMS_CONTROL_AB__
-#define __SYSTEM_WINDOWS_FORMS_CONTROL_AB__
-
-/*
-#require <Classes/System/Windows/Forms/misc.ab>
-#require <Classes/System/Windows/Forms/CreateParams.ab>
-#require <Classes/System/Windows/Forms/Message.ab>
-#require <Classes/System/Windows/Forms/PaintEventArgs.ab>
-#require <Classes/System/misc.ab>
-#require <Classes/System/Math.ab>
-#require <Classes/System/Threading/WaitHandle.ab>
-*/
-#require <Classes/System/Drawing/Color.ab>
-#require <Classes/System/Drawing/Point.ab>
-#require <Classes/System/Drawing/Size.ab>
-#require <Classes/System/Drawing/Rectangle.ab>
-/*
-#require <Classes/System/Runtime/InteropServices/GCHandle.ab>
-#require <Classes/ActiveBasic/Windows/WindowHandle.sbp>
-#require <Classes/ActiveBasic/Strings/Strings.ab>
-*/
 Namespace System
 Namespace Windows
@@ -77,6 +56,5 @@
 
 Class Control
-
-'	Inherits IWin32Window
+	Implements IWin32Window
 Public
 	'---------------------------------------------------------------------------
@@ -100,5 +78,5 @@
 	'CheckForIllegalCrossThreadCalls
 
-	/*Override*/ Function Handle() As HWND
+	Override Function Handle() As HWND
 		Return wnd.HWnd
 	End Function
@@ -301,6 +279,26 @@
 
 	Sub init(parent As Control, text As String, left As Long, top As Long, width As Long, height As Long)
+		This.text = text
 		This.parent = parent
-'		CreateControl()
+
+		Dim rgb = GetSysColor( COLOR_HIGHLIGHT )
+		This.bkColor = New Color( GetRValue(rgb) As Byte, GetGValue(rgb) As Byte, GetBValue(rgb) As Byte )
+
+		Dim hParentWnd = NULL As HWND
+		If Not ActiveBasic.IsNothing( parent ) Then
+			hParentWnd = parent.Handle
+		End If
+
+		createParams = New CreateParams()
+		With createParams
+			.Caption = text
+			.X = left
+			.Y = top
+			.Width = width
+			.Height = height
+			.Parent = hParentWnd
+		End With
+
+		CreateControl()
 	End Sub
 	
@@ -358,6 +356,9 @@
 		If IsWindow(hwnd) Then
 			If GetClassLongPtr(hwnd, GCW_ATOM) = atom Then
-				Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(GetWindowLongPtr(hwnd, GWLP_THIS))
-				Return gch.Target As Control
+				Dim lpValue = GetWindowLongPtr(hwnd, GWLP_THIS)
+				If lpValue Then
+					Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr( lpValue )
+					Return gch.Target As Control
+				End If
 			End If
 		End If
@@ -370,5 +371,5 @@
 
 	Override Function ToString() As String
-		Return text
+		Return Super.ToString + ", Text: " + This.Text
 	End Function
 
@@ -383,5 +384,4 @@
 
 	Sub Show()
-		Debug
 		wnd.Show(SW_SHOW)
 	End Sub
@@ -418,5 +418,4 @@
 	' Protected Methods
 	Virtual Sub CreateHandle()
-		Debug
 		If Not Object.ReferenceEquals(wnd, Nothing) Then
 			If wnd.HWnd <> 0 Then
@@ -424,29 +423,42 @@
 			End If
 		End If
-		
-		Dim createParams = CreateParams()
+
 		Dim gch = System.Runtime.InteropServices.GCHandle.Alloc(This)
 		TlsSetValue(tlsIndex, System.Runtime.InteropServices.GCHandle.ToIntPtr(gch) As VoidPtr)
-		With createParams
-			Dim pText As PCTSTR
-			If String.IsNullOrEmpty(text) Then
-				pText = "" As PCTSTR
-			Else
-				pText = ToTCStr(text)
-			End If
-
-			If CreateWindowEx(.ExStyle, atom As ULONG_PTR As PCSTR, pText, .Style, _
-				.X, .Y, .Width, .Height, _
-				.Parent, 0, hInstance, 0) = 0 Then
-				' Error
-				Dim buf[1023] As TCHAR
-				wsprintf(buf, ToTCStr(Ex"Control: CreateWindowEx failed. Error code: &h%08X\r\n"), GetLastError())
-				OutputDebugString(buf)
-
-				gch.Free()
+
+		Dim pText As PCTSTR
+		If String.IsNullOrEmpty(text) Then
+			pText = "" As PCTSTR
+		Else
+			pText = ToTCStr(text)
+		End If
+
+		Dim result As HANDLE
+		With This.CreateParams
+			result = CreateWindowEx(
+				.ExStyle,						' 拡張ウィンドウ スタイル
+				atom As ULONG_PTR As PCSTR,		' クラス名
+				pText,							' キャプション
+				.Style,							' ウィンドウ スタイル
+				.X,								' X座標
+				.Y,								' Y座標
+				.Width,							' 幅
+				.Height,						' 高さ
+				.Parent,						' 親ウィンドウ ハンドル
+				0,								' メニュー ハンドル
+				hInstance,						' アプリケーション インスタンス ハンドル
+				0)								' ウィンドウ作成データ
+		End With
+
+		If result = NULL Then
+			' Error
+			Dim buf[1023] As TCHAR
+			wsprintf(buf, ToTCStr(Ex"Control: CreateWindowEx failed. Error code: &h%08X\r\n"), GetLastError())
+			OutputDebugString(buf)
+
+			gch.Free()
 '				Debug
-				ExitThread(0)
-			End If
-		End With
+			ExitThread(0)
+		End If
 		
 	End Sub
@@ -549,9 +561,8 @@
 	' Member variables
 	wnd As ActiveBasic.Windows.WindowHandle
+	createParams As CreateParams
 	text As String
 	parent As Control
 	bkColor As Color
-
-	Static createParams As CreateParams
 
 	'ウィンドウ作成時にウィンドウプロシージャへThisを伝えるためのもの
@@ -593,15 +604,4 @@
 			ExitThread(0)
 		End If
-
-		With createParams
-			' 値は暫定的なもの
-			.Style = WS_OVERLAPPEDWINDOW
-			.ExStyle = WS_EX_APPWINDOW
-			.Caption = String.Empty
-			.X = 0
-			.Y = 0
-			.Width = 0
-			.Height = 0
-		End With
 	End Sub
 
@@ -672,5 +672,2 @@
 End Namespace 'Widnows
 End Namespace 'System
-
-#endif '__SYSTEM_WINDOWS_FORMS_CONTROL_AB__
-
