'Classes/ActiveBasic/Windows/WindowHandle.sbp

#ifdef _WIN64
Declare Function _System_GetClassLongPtr Lib "user32" Alias _FuncName_GetClassLongPtr (hWnd As HWND, nIndex As Long) As LONG_PTR
Declare Function _System_SetClassLongPtr Lib "user32" Alias _FuncName_SetClassLongPtr (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR
Declare Function _System_GetWindowLongPtr Lib "user32" Alias _FuncName_GetWindowLongPtr (hWnd As HWND, nIndex As Long) As LONG_PTR
Declare Function _System_SetWindowLongPtr Lib "user32" Alias _FuncName_SetWindowLongPtr (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR
#else
Declare Function _System_GetClassLongPtr Lib "user32" Alias _FuncName_GetClassLong (hWnd As HWND, nIndex As Long) As LONG_PTR
Declare Function _System_SetClassLongPtr Lib "user32" Alias _FuncName_SetClassLong (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR
Declare Function _System_GetWindowLongPtr Lib "user32" Alias _FuncName_GetWindowLong (hWnd As HWND, nIndex As Long) As LONG_PTR
Declare Function _System_SetWindowLongPtr Lib "user32" Alias _FuncName_SetWindowLong (hWnd As HWND, nIndex As Long, l As LONG_PTR) As LONG_PTR
#endif
Declare Function _System_GetParent Lib "user32" Alias "GetParent" (hWnd As HWND) As HWND
Declare Function _System_SetParent Lib "user32" Alias "SetParent" (hWnd As HWND, hwndParent As HWND) As HWND
Declare Function _System_GetMenu Lib "user32" Alias "GetMenu" (hWnd As HWND) As HMENU
Declare Function _System_SetMenu Lib "user32" Alias "SetMenu" (hWnd As HWND, hmenu As HMENU) As HMENU
Declare Function _System_InvalidateRect Lib "user32" Alias "InvalidateRect" (hWnd As HWND, ByRef Rect As RECT, bErase As BOOL) As BOOL
Declare Function _System_InvalidateRgn Lib "user32" Alias "InvalidateRgn" (hWnd As HWND, hRgn As HRGN, bErase As BOOL) As BOOL
Declare Function _System_ValidateRect Lib "user32" Alias "ValidateRect" (hWnd As HWND, ByRef Rect As RECT) As BOOL
Declare Function _System_ValidateRgn Lib "user32" Alias "ValidateRgn" (hWnd As HWND, hRgn As HRGN) As BOOL
Declare Function _System_BeginPaint Lib "user32" Alias "BeginPaint" (hWnd As HWND, ByRef ps As PAINTSTRUCT) As HDC
Declare Function _System_EndPaint Lib "user32" Alias "EndPaint" (hWnd As HWND, ByRef ps As PAINTSTRUCT) As HDC
Declare Function _System_ClientToScreen Lib "user32" Alias "ClientToScreen" (hWnd As HWND, ByRef Point As POINTAPI) As BOOL
Declare Function _System_ScreenToClient Lib "user32" Alias "ScreenToClient" (hWnd As HWND, ByRef Point As POINTAPI) As BOOL
Declare Function _System_CreateCaret Lib "user32" Alias "CreateCaret" (hWnd As HWND, hBitmap As HBITMAP, nWidth As Long, nHeight As Long) As BOOL
Declare Function _System_HideCaret Lib "user32" Alias "HideCaret" (hWnd As HWND) As BOOL
Declare Function _System_ShowCaret Lib "user32" Alias "ShowCaret" (hWnd As HWND) As BOOL
Declare Function _System_DrawMenuBar Lib "user32" Alias "DrawMenuBar" (hwnd As HWND) As BOOL
Declare Function _System_GetWindowRect Lib "user32" Alias "DrawMenuBar" (hWnd As HWND, ByRef Rect As RECT) As BOOL
Declare Function _System_IsWindow Lib "user32" Alias "IsWindow" (hWnd As HWND) As BOOL
Declare Function _System_IsIconic Lib "user32" Alias "IsIconic" (hWnd As HWND) As BOOL
Declare Function _System_GetClientRect Lib "user32" Alias "GetClientRect" (hWnd As HWND, ByRef Rect As RECT) As BOOL
Declare Function _System_GetProp Lib "user32" Alias _FuncName_GetProp (hWnd As HWND, pString As PCTSTR) As HANDLE
Declare Function _System_SetProp Lib "user32" Alias _FuncName_SetProp (hWnd As HWND, pString As PCTSTR, hData As HANDLE) As BOOL
Declare Function _System_GetClassName Lib "user32" Alias _FuncName_GetClassName (hWnd As HWND, lpClassName As PTSTR, nMaxCount As Long) As Long
Declare Function _System_GetScrollInfo Lib "user32" Alias "GetScrollInfo" (hWnd As HWND, fnBar As Long, ByRef lpsi As SCROLLINFO) As BOOL
Declare Function _System_SetScrollInfo Lib "user32" Alias "SetScrollInfo" (hWnd As HWND, fnBar As Long, ByRef lpsi As SCROLLINFO, bRedraw As Long) As BOOL
Declare Function _System_GetSystemMenu Lib "user32" Alias "GetSystemMenu" (hWnd As HWND, bRevert As BOOL) As HMENU
Declare Function _System_GetDC Lib "user32" Alias "GetDC" (hwnd As HWND) As HDC
Declare Function _System_GetDCEx Lib "user32" Alias "GetDCEx" (hwnd As HWND, hrgnClip As HRGN, flags As DWord) As HDC
Declare Function _System_GetWindowDC Lib "user32" Alias "GetWindowDC" (hwnd As HWND) As HDC
Declare Function _System_ReleaseDC Lib "user32" Alias "ReleaseDC" (hwnd As HWND, hdc As HDC) As BOOL
Declare Function _System_SendMessage Lib "user32" Alias _FuncName_SendMessage (hwnd As HWND, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
Declare Function _System_PostMessage Lib "user32" Alias _FuncName_PostMessage (hwnd As HWND, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
Declare Function _System_SendDlgItemMessage Lib "user32" Alias _FuncName_SendDlgItemMessage (hwnd As HWND, id As DWord, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
Declare Function _System_GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (hwnd As HWND, pdwProcessId As *DWord) As DWord

Namespace ActiveBasic
Namespace Windows

Class WindowHandle
	hwnd As HWND
Public
	Sub WindowHandle()
		hwnd = 0
	End Sub

	Sub WindowHandle(hwndNew As HWND)
		hwnd = hwndNew
	End Sub

	Const Function HWnd() As HWND
		Return hwnd
	End Function

	Const Function Operator() As HWND
		Return hwnd
	End Function

	Function BringToTop() As Boolean
		Return BringWindowToTop(hwnd) As Boolean
	End Function

	Function BeginPaint(ByRef ps As PAINTSTRUCT) As HDC
		Return _System_BeginPaint(hwnd, ps)
	End Function
/*
	Const Function ChildFromPoint(x As Long, y As Long) As WindowHandle
		Return New WindowHandle(ChildWindowFromPoint(hwnd, x, y))
	End Function

	Const Function ChildFromPointEx(x As Long, y As Long, flags As DWord) As WindowHandle
		Return New WindowHandle(ChildWindowFromPointEx(hwnd, x, y, flags))
	End Function
*/
	Const Function ClientToScreen(ByRef pt As POINTAPI) As Boolean
		Return _System_ClientToScreen(hwnd, pt) As Boolean
	End Function

	Const Function ClientToScreen(ByRef rc As RECT) As Boolean
		Dim ppt = VarPtr(rc) As *POINTAPI
		Return (_System_ClientToScreen(hwnd, ppt[0]) <> FALSE And _System_ClientToScreen(hwnd, ppt[1]) <> FALSE) As Boolean
	End Function

	Function Close() As Boolean
		Return CloseWindow(hwnd) As Boolean
	End Function

	Function CreateCaret(hbmp As HBITMAP, width As Long, height As Long) As Boolean
		Return _System_CreateCaret(hwnd, hbmp, width, height) As Boolean
	End Function

	Function Destroy() As Boolean
		Return DestroyWindow(hwnd) As Boolean
	End Function

	Function DrawMenuBar() As Boolean
		Return _System_DrawMenuBar(hwnd) As Boolean
	End Function
/*
	Function EnableScrollBar(SBFlags As DWord, arrows As DWord) As Boolean
		Return EnableScrollBar(hwnd, SBFlags, arrows) As Boolean
	End Function
*/
	Function Enable(enable As Boolean) As Boolean
		Return EnableWindow(hwnd, enable) As Boolean
	End Function

	Function EndPaint(ByRef ps As PAINTSTRUCT) As Boolean
		Return _System_EndPaint(hwnd, ps) As Boolean
	End Function

	Const Function EnumChilds(enumFunc As WNDENUMPROC, lp As LPARAM) As Boolean
		Return EnumChildWindows(hwnd, enumFunc, lp) As Boolean
	End Function

	Function Flash(invert As Boolean) As Boolean
		Return FlashWindow(hwnd, invert) As Boolean
	End Function

	Const Function GetClassLongPtr(index As Long) As LONG_PTR
		Return _System_GetClassLongPtr(hwnd, index)
	End Function

	Const Function GetClassName(className As PTSTR, maxCount As Long) As Long
		Return _System_GetClassName(hwnd, className, maxCount)
	End Function

	Const Function GetClientRect(ByRef rc As RECT) As Boolean
		Return _System_GetClientRect(hwnd, rc) As Boolean
	End Function
/*
	Const Function GetContextHelpId() As DWord
		Return GetWindowContextHelpId(hwnd)
	End Function
*/
	Function GetDC() As HDC
		Return _System_GetDC(hwnd)
	End Function

	Function GetDCEx(hrgnClip As HRGN, flags As DWord) As HDC
		Return _System_GetDCEx(hwnd, hrgnClip, flags)
	End Function
/*
	Const Function GetDlgCtrlID() As Long
		Return GetDlgCtrlID(hwnd)
	End Function

	Const Function GetDlgItem(idDlgItem As Long) As WindowHandle
		Return GetDlgItem(hwnd, idDlgItem)
	End Function

	Const Function GetDlgItemText(idDlgItem As Long, ps As PTSTR, maxCount As Long) As Long
		Return GetDlgItemText(hwnd, idDlgItem, ps, maxCount)
	End Function
*/
	Const Function GetMenu() As HMENU
		Return _System_GetMenu(hwnd)
	End Function
/*
	Const Function GetParent() As WindowHandle
		Return New WindowHandle(_System_GetParent(hwnd))
	End Function
*/
	Const Function GetProp(str As String) As HANDLE
		Return _System_GetProp(hwnd, ToTCStr(str))
	End Function

	Const Function GetProp(psz As PCTSTR) As HANDLE
		Return _System_GetProp(hwnd, psz)
	End Function

	Const Function GetProp(atom As ATOM) As HANDLE
		Return _System_GetProp(hwnd, atom As ULONG_PTR As PCTSTR)
	End Function

	Const Function GetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO) As Boolean
		Return _System_GetScrollInfo(hwnd, fnBar, si) As Boolean
	End Function
/*
	Const Function GetSystemMenu(revert As Boolean) As HMENU
		Return GetSystemMenu(hwnd, revert)
	End Function

	Const Function GetUpdateRect(ByRef rc As RECT, erase As Boolean) As Boolean
		Return GetUpdateRact(hwnd, rc, erase) As Boolean
	End Function

	Const Function GetUpdateRgn(hrgn As HRGN, erase As Boolean) As Boolean
		Return GetUpdateRgn(hwnd, hrgn, erase) As Boolean
	End Function

	Const Function GetWindow(cmd As DWord) As WindowHandle
		Return GetWindow(hwnd, cmd)
	End Function
*/
	Function GetWindowDC() As HDC
		Return _System_GetWindowDC(hwnd)
	End Function

	Const Function GetWindowLongPtr(index As Long) As LONG_PTR
		Return _System_GetWindowLongPtr(hwnd, index)
	End Function
/*
	Const Function GetWindowPlasement(ByRef wndpl As WINDOWPLACEMENT) As Boolean
		Return GetWindowPlasement(hwnd, wndpl) As Boolean
	End Function
*/
	Const Function GetWindowRect(ByRef rc As RECT) As Boolean
		Return _System_GetWindowRect(hwnd, rc) As Boolean
	End Function

	Const Function GetText(ps As PTSTR, maxCount As Long) As Boolean
		Return GetWindowText(hwnd, ps, maxCount) As Boolean
	End Function

	Const Function GetTextLength() As Long
		Return GetWindowTextLength(hwnd)
	End Function

	Const Function GetWindowThreadId() As DWord
		Return _System_GetWindowThreadProcessId(hwnd, 0)
	End Function

	Const Function GetWindowThreadProcessId(ByRef processId As DWord) As DWord
		Return _System_GetWindowThreadProcessId(hwnd, VarPtr(processId))
	End Function

	Function HideCaret() As Boolean
		Return _System_HideCaret(hwnd) As Boolean
	End Function

	Function InvalidateRect(ByRef rc As RECT, erace As Boolean) As Boolean
		Return _System_InvalidateRect(hwnd, rc, erace) As Boolean
	End Function

	Function InvalidateRect(ByRef rc As RECT) As Boolean
		Return _System_InvalidateRect(hwnd, rc, TRUE) As Boolean
	End Function

	Function InvalidateRgn(hrgn As HRGN, erace As Boolean) As Boolean
		Return _System_InvalidateRgn(hwnd, hrgn, erace) As Boolean
	End Function

	Function InvalidateRgn(hrgn As HRGN) As Boolean
		Return _System_InvalidateRgn(hwnd, hrgn, TRUE) As Boolean
	End Function

	Function Invalidate(erace As Boolean) As Boolean
		Return _System_InvalidateRect(hwnd, ByVal 0, erace) As Boolean
	End Function

	Function Invalidate() As Boolean
		Return _System_InvalidateRect(hwnd, ByVal 0, TRUE) As Boolean
	End Function
/*
	Const Function IsChild(hwnd As HWND) As Boolean
		Return IsChild(This.hwnd, hwnd) As Boolean
	End Function

	Const Function IsDialogMessage(ByRef msg As MSG) As Boolean
		Return IsDialogMessage(hwnd, msg) As Boolean
	End Function
*/
	Const Function IsIconic() As Boolean
		Return _System_IsIconic(hwnd) As Boolean
	End Function

	Const Function IsWindow() As Boolean
		Return _System_IsWindow(hwnd) As Boolean
	End Function

	Const Function IsEnabled() As Boolean
		Return IsWindowEnabled(hwnd) As Boolean
	End Function

	Const Function IsUnicode() As Boolean
		Return IsWindowUnicode(hwnd) As Boolean
	End Function

	Const Function IsVisible() As Boolean
		Return IsWindowVisible(hwnd) As Boolean
	End Function
/*
	Const Function IsZoomed() As Boolean
		Return IsZoomed(hwnd) As Boolean
	End Function

	Function KillTimer(idEvent As ULONG_PTR) As Boolean
		Return KillTimer(idEvent) As Boolean
	End Function
*/
	Function LockUpdate() As Boolean
		Return LockWindowUpdate(hwnd) As Boolean
	End Function
/*
	Function MapPoints(hwndTo As HWND, pPoints As *POINTAPI, cPoints As DWord) As Long
		Return MapWindowPoints(hwnd, hwndTo, pPoints, cPoints)
	End Function

	Function MapPoints(hwndTo As HWND, ByRef rc As RECT) As Long
		Return MapWindowPoints(hwnd, hwndTo, VarPtr(rc) As *POINTAPI, 2)
	End Function

	Const Function MessageBox(text As PCTSTR, caption As PCTSTR, uType As DWord) As Long
		Return MessageBox(hwnd, text, caption, uType)
	End Function

	Const Function MessageBox(text As PCTSTR, caption As PCTSTR) As Long
		Return MessageBox(hwnd, text, caption, MB_OK)
	End Function

	Const Function MessageBox(text As PCTSTR) As Long
		Return MessageBox(hwnd, text, 0, MB_OK)
	End Function
*/
	Function Move(x As Long, y As Long, width As Long, height As Long, repaint 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
		With rc
			Return MoveWindow(hwnd, .left, .top, .right - .left, .bottom - .top, repaint) As Boolean
		End With
	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
		Return OpenClipboard(hwnd) As Boolean
	End Function

	Function OpenIcon() As Boolean
		Return OpenIcon(hwnd) As Boolean
	End Function
*/
	Function PostMessage(msg As DWord, wp As WPARAM, lp As LPARAM) As Boolean
		Return _System_PostMessage(hwnd, msg, wp, lp) As Boolean
	End Function

	Function PostMessage(msg As DWord) As Boolean
		Return _System_PostMessage(hwnd, msg, 0, 0) As Boolean
	End Function
/*
	Function RedrawWindow(ByRef rcUpdate As RECT, hrgnUpdate As HRGN, flags As DWord) As Boolean
		Return RedrawWindow(hwnd, rcUpdatre, hrgnUpdate, flags) As Boolean
	End Function
*/
	Function ReleaseDC(hdc As HDC) As Boolean
		Return _System_ReleaseDC(hwnd, hdc) As Boolean
	End Function
/*
	Function RemoveProp(str As String) As HANDLE
		Return RemoveProp(hwnd, ToTCStr(str))
	End Function

	Function RemoveProp(psz As PCTSTR) As HANDLE
		Return RemoveProp(hwnd, psz)
	End Function

	Function RemoveProp(atom As ATOM) As HANDLE
		Return RemoveProp(hwnd, atom As ULONG_PTR As PCTSTR)
	End Function
*/
	Const Function ScreenToClient(ByRef pt As POINTAPI) As Boolean
		Return _System_ScreenToClient(hwnd, pt) As Boolean
	End Function

	Const Function ScreenToClient(ByRef rc As RECT) As Boolean
		Dim ppt = VarPtr(rc) As *POINTAPI
		Return (_System_ScreenToClient(hwnd, ppt[0]) <> FALSE And _System_ScreenToClient(hwnd, ppt[1]) <> FALSE) As Boolean
	End Function

	Function Scroll(dx As Long, dy As Long, ByRef rcScroll As RECT, ByRef rcClip As RECT, hrgnUpdate As HRGN, ByRef rcUpdate As RECT, flags As DWord) As Boolean
		Return ScrollWindowEx(hwnd, dx, dy, rcScroll, rcClip, hrgnUpdate, rcUpdate, flags) As Boolean
	End Function

	Function SendDlgItemMessage(idDlgItem As Long, msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
		Return _System_SendDlgItemMessage(hwnd, idDlgItem, msg, wp, lp)
	End Function

	Function SendDlgItemMessage(idDlgItem As Long, msg As DWord) As LRESULT
		Return _System_SendDlgItemMessage(hwnd, idDlgItem, msg, 0, 0)
	End Function

	Function SendMessage(msg As DWord, wp As WPARAM, lp As LPARAM) As LRESULT
		Return _System_SendMessage(hwnd, msg, wp, lp)
	End Function

	Function SendMessage(msg As DWord) As LRESULT
		Return _System_SendMessage(hwnd, msg, 0, 0)
	End Function
/*
	Function SetActiveWindow() As WindowHandle
		Return New WindowHandle(SetActiveWindow(hwnd))
	End Function

	Function SetDlgItemText(idDlgItem As Long, psz As PCTSTR) As Boolean
		Return SetDlgItemText(hwnd, idDlgItem, psz) As Boolean
	End Function

	Function SetCapture() As WindowHandle
		Return New WindowHandle(SetCapture(hwnd))
	End Function
*/
	Function SetClassLongPtr(index As Long, newLong As LONG_PTR) As LONG_PTR
		Return _System_SetClassLongPtr(hwnd, index, newLong)
	End Function
/*
	Function SetFocus() As WindowHandle
		Return New WindowHandle(SetFocus(hwnd))
	End Function
*/
	Function SetForeground() As Boolean
		Return SetForegroundWindow(hwnd) As Boolean
	End Function

	Function SetMenu(hmenu As HMENU) As Boolean
		Return _System_SetMenu(hwnd, hmenu) As Boolean
	End Function

	Function SetParent(hwndNewParent As HWND) As WindowHandle
		Return New WindowHandle(_System_SetParent(hwnd, hwndNewParent))
	End Function

	Function SetProp(str As String, hData As HANDLE) As Boolean
		Return _System_SetProp(hwnd, ToTCStr(str), hData) As Boolean
	End Function

	Function SetProp(psz As PCTSTR, hData As HANDLE) As Boolean
		Return _System_SetProp(hwnd, psz, hData) As Boolean
	End Function

	Function SetProp(atom As ATOM, hData As HANDLE) As Boolean
		Return This.SetProp((atom As ULONG_PTR) As PCTSTR, hData) As Boolean
	End Function

	Function SetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO, redraw As Boolean) As Boolean
		Return _System_SetScrollInfo(hwnd, fnBar, si, redraw) As Boolean
	End Function

	Function SetScrollInfo(fnBar As Long, ByRef si As SCROLLINFO) As Boolean
		Return _System_SetScrollInfo(hwnd, fnBar, si, TRUE) As Boolean
	End Function
/*
	Function SetTimer(idEvent As ULONG_PTR, elapse As DWord, timerFunc As TIMERPROC) As ULONG_PTR
		Return SetTmer(hwnd, idEvent, elapse, timerFunc)
	End Function

	Function SetTimer(idEvent As ULONG_PTR, elapse As DWord) As ULONG_PTR
		Return This.SetTmer(hwnd, idEvent, elapse, 0)
	End Function

	Function SetContextHelpId(contextHelpId As DWord) As Boolean
		Return SetContextHelpId(hwnd, contextHelpId) As Boolean
	End Function
*/
	Function SetWindowLongPtr(index As Long, newLong As LONG_PTR) As LONG_PTR
		Return _System_SetWindowLongPtr(hwnd, index, newLong)
	End Function
/*
	Function SetWindowPlacement(ByRef wndpl As WINDOWPLACEMENT) As Boolean
		Return SetWindowPlacement(hwnd, wndpl) As Boolean
	End Function
*/
	Function SetPos(hwndInsertAfter As HWND, x As Long, y As Long, cx As Long, cy As Long, flags As DWord) As Boolean
		Return SetWindowPos(hwnd, hwndInsertAfter, x, y, cx, cy, flags) As Boolean
	End Function

	Function SetPos(hwndInsertAfter As HWND, ByRef rc As RECT, flags As DWord) As Boolean
		With rc
			Return SetWindowPos(hwnd, hwndInsertAfter, .left, .top, .right - .left, .bottom - .top, flags) As Boolean
		End With
	End Function

	Function SetRgn(hrgn As HRGN, redraw As Boolean) As Boolean
		Return SetWindowRgn(hwnd, hrgn, redraw) As Boolean
	End Function

	Function SetRgn(hrgn As HRGN) As Boolean
		Return SetWindowRgn(hwnd, hrgn, TRUE) As Boolean
	End Function

	Function SetText(psz As PCTSTR) As Boolean
		Return SetWindowText(hwnd, psz) As Boolean
	End Function

	Function SetText(str As String) As Boolean
		Return SetWindowText(hwnd, ToTCStr(str)) As Boolean
	End Function

	Function ShowCaret() As Boolean
		Return _System_ShowCaret(hwnd) As Boolean
	End Function
/*
	Function ShowScrollBar(bar As DWord, show As Boolean) As Boolean
		Return ShowScrollBar(hwnd, bar, show) As Boolean
	End Function

	Function ShowScrollBar(bar As DWord) As Boolean
		Return ShowScrollBar(hwnd, bar, TRUE) As Boolean
	End Function
*/
	Function Show(cmdShow As DWord) As Boolean
		Return ShowWindow(hwnd, cmdShow) As Boolean
	End Function

	Function ShowAsync(cmdShow As DWord) As Boolean
		Return ShowWindowAsync(hwnd, cmdShow) As Boolean
	End Function

	Function Update() As Boolean
		Return UpdateWindow(hwnd) As Boolean
	End Function

	Function ValidateRect(ByRef rc As RECT) As Boolean
		Return _System_ValidateRect(hwnd, rc) As Boolean
	End Function

	Function ValidateRgn(hrgn As HRGN) As Boolean
		Return _System_ValidateRgn(hwnd, hrgn) As Boolean
	End Function

	Function Validate() As Boolean
		Return _System_ValidateRect(hwnd, ByVal 0) As Boolean
	End Function

	' Get/SetWindowLongPtr Wrappers

	Const Function GetExStyle() As DWord
		Return _System_GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord
	End Function

	Const Function GetStyle() As DWord
		Return _System_GetWindowLongPtr(hwnd, GWL_STYLE) As DWord
	End Function
#ifdef _UNDEF
	Const Function GetWndProc() As WNDPROC
		Return _System_GetWindowLongPtr(hwnd, GWLP_WNDPROC) As WNDPROC
	End Function
#endif
	Const Function GetInstance() As HINSTANCE
		Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE
	End Function

	Const Function GetUserData() As LONG_PTR
		Return _System_GetWindowLongPtr(hwnd, GWLP_USERDATA)
	End Function

	Function SetExStyle(style As DWord) As DWord
		Return _System_SetWindowLongPtr(hwnd, GWL_EXSTYLE, style) As DWord
	End Function

	Function SetStyle(style As DWord) As DWord
		Return _System_SetWindowLongPtr(hwnd, GWL_STYLE, style) As DWord
	End Function
#ifdef _UNDEF
	Function SetWndProc(wndProc As WNDPROC) As WNDPROC
		Return _System_SetWindowLongPtr(hwnd, GWLP_WNDPROC, wndProc As WNDPROC) As WNDPROC
	End Function
#endif
	Function SetUserData(value As LONG_PTR) As LONG_PTR
		Return _System_SetWindowLongPtr(hwnd, GWLP_USERDATA, value As LONG_PTR)
	End Function

	' Propaties

	Const Function ClientRect() As RECT
		_System_GetClientRect(hwnd, ClientRect)
	End Function
#ifdef _UNDEF
	Sub ClientRect(ByRef rc As RECT)
		Dim hasMenu As BOOL
		If IsChild() = False And GetMenu() <> 0 Then
			hasMenu = TRUE
		Else
			hasMenu = FALSE
		End If
		AdjustWindowRectEx(rc, GetStyle(), hasMenu, GetExStyle())
		This.Move(rc) ' WindowRect = rc
	End Sub
#endif
	Const Function WindowRect() As RECT
		_System_GetWindowRect(hwnd, WindowRect)
	End Function

	Sub WindowRect(ByRef rc As RECT)
		This.Move(rc)
	End Sub
#ifdef _UNDEF
	Const Function ContextHelpID() As DWord
		Return GetContextHelpId(hwnd)
	End Function

	Sub ContextHelpID(newID As DWord)
		_System_SetContextHelpId(hwnd, newId)
	End Sub

	Const Function DlgCtrlID() As Long
		Return GetDlgCtrlID(hwnd)
	End Function

	Sub DlgCtrlId(newId As Long)
		_System_SetWindowLongPtr(hwnd, GWLP_ID, newId)
	End Sub

	Function DlgItem(idDlgItem As Long) As WindowHandle
		Dim w As WindowHandle(GetDlgItem(hwnd, idDlgItem))
		Return w
	End Function
#endif
	Const Function ExStyle() As DWord
		Return _System_GetWindowLongPtr(hwnd, GWL_EXSTYLE) As DWord
	End Function

	Sub ExStyle(newExStyle As DWord)
		_System_SetWindowLongPtr(hwnd, GWL_EXSTYLE, newExStyle)
	End Sub

	Const Function Style() As DWord
		Return _System_GetWindowLongPtr(hwnd, GWL_STYLE) As DWord
	End Function

	Sub Style(newStyle As DWord)
		_System_SetWindowLongPtr(hwnd, GWL_STYLE, newStyle)
	End Sub

	Const Function Enabled() As Boolean
		Return IsWindowEnabled(hwnd) As Boolean
	End Function

	Sub Enabled(enable As Boolean)
		EnableWindow(hwnd, enable)
	End Sub

	Const Function Font() As HFONT
		Return _System_SendMessage(hwnd, WM_GETFONT, 0, 0) As HFONT
	End Function

	Sub Font(hfntNew As HFONT)
		_System_SendMessage(hwnd, WM_SETFONT, hfntNew As WPARAM, TRUE)
	End Sub

	Const Function Maximized() As Boolean
		Return IsIconic() As Boolean
	End Function

	Sub Maximized(maximized As Boolean)
		If maximized <> False Then
			ShowWindow(hwnd, SW_SHOWMAXIMIZED)
		Else
			ShowWindow(hwnd, SW_RESTORE)
		End If
	End Sub

	Const Function Minimized() As Boolean
		Return _System_IsIconic(hwnd) As Boolean
	End Function

	Sub Minimized(minimized As Boolean)
		If minimized <> False Then
			CloseWindow(hwnd)
		Else
			OpenIcon(hwnd)
		End If
	End Sub

	Const Function Instance() As HINSTANCE
		Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As HINSTANCE
	End Function

	' IsWindow, IsUnicodeはメソッドと同じ。

	Const Function Parent() As WindowHandle
		Return New WindowHandle(_System_GetParent(hwnd))
	End Function

	Sub Parent(hwndNewParent As HWND)
		_System_SetParent(hwnd, hwndNewParent)
	End Sub

	Const Function ProcessId() As DWord
		GetWindowThreadProcessId(ProcessId)
	End Function

	Const Function ThreadId() As DWord
		Return GetWindowThreadProcessId(ByVal 0)
	End Function

	Const Function Menu() As HMENU
		Return _System_GetMenu(hwnd)
	End Function

	Sub Menu(hmenuNew As HMENU)
		_System_SetMenu(hwnd, hmenuNew)
	End Sub

	Const Function Prop(str As String) As HANDLE
		Return GetProp(str)
	End Function

	Const Function Prop(psz As PCTSTR) As HANDLE
		Return GetProp(psz)
	End Function

	Const Function Prop(atom As ATOM) As HANDLE
		Return GetProp(atom)
	End Function

	Sub Prop(str As PCTSTR, h As HANDLE)
		SetProp(str, h)
	End Sub

	Sub Prop(atom As ATOM, h As HANDLE)
		SetProp(atom, h)
	End Sub

	Const Function Text() As String
		Dim size = GetWindowTextLength(hwnd) + 1
		Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PTSTR
		Dim length = GetWindowText(hwnd, p, size)
		Text = New String(p, length As Long)
	End Function

	Sub Text(newText As String)
		SetWindowText(hwnd, ToTCStr(newText))
	End Sub

	Sub Text(newText As PCTSTR)
		SetWindowText(hwnd, newText)
	End Sub

	Const Function TextLength() As Long
		Return GetWindowTextLength(hwnd)
	End Function
#ifdef _UNDEF
	Const Function UserData() As LONG_PTR
		Return _System_GetWindowLongPtr(hwnd, GWLP_USERDATA)
	End Function

	Sub UserData(newValue As LONG_PTR)
		_System_SetWindowLongPtr(hwnd, GWLP_USERDATA, newValue)
	End Sub
#endif
	Const Function Visible() As Boolean
		Return IsWindowVisible(hwnd) As Boolean
	End Function

	Sub Visible(visible As Boolean)
		If visible <> False Then
			ShowWindow(hwnd, SW_SHOW)
		Else
			ShowWindow(hwnd, SW_HIDE)
		EndIf
	End Sub
#ifdef _UNDEF
	Const Function WindowPlacement() As WINDOWPLACEMENT
		WindowPlacement.length = Len(WindowPlacement)
		GetWindowPlacement(hwnd, WindowPlacement)
	End Function

	Sub WindowPlacement(ByRef wndpl As WINDOWPLACEMENT)
		SetWindowPlacement(wndpl)
	End Sub

	Const Function WndProc() As WNDPROC
		Return _System_GetWindowLongPtr(hwnd, GWLP_HINSTANCE) As WNDPROC
	End Function

	Sub WndProc(newWndProc As WNDPROC)
		_System_SetWindowLongPtr(hwnd, GWLP_WNDPROC, newWndProc As LONG_PTR)
	End Sub
#endif
Protected
	Sub SetHWnd(hwndNew As HWND)
		hwnd = hwndNew
	End Sub
End Class

End Namespace 'Widnows
End Namespace 'ActiveBasic
