#include once "window9.bi"

#Ifdef UNICODE
	Function GetWindowText overload(byval hwnd As HWND) As USTRING export
		Dim As Integer L=GetWindowTextLength(hwnd)
		dim as USTRING sRet = wspace(L+1)
		SendMessage(hwnd,WM_GETTEXT,L+1,Cast(LParam,*sRet))
		return sRet
	End Function
	Function GetWindowText OverLoad(byval hwnd as HWND, byval buf as any ptr, byval lenBuf as integer) as Integer Export	
		Return SendMessage(hwnd,WM_GETTEXT,lenBuf,Cast(LParam,buf))
	End Function
#else
	Function GetWindowText overload(byval hwnd As HWND) As USTRING export
		Dim As Integer L=GetWindowTextLength(hwnd)
		Dim As Byte Ptr fbguiTextBuffer = Allocate (L+1)
		if fbguiTextBuffer then
			SendMessage(hwnd,WM_GETTEXT,L+1,Cast(LPARAM,fbguiTextBuffer))
			Function = PeekS(fbguiTextBuffer)
			DeAllocate (fbguiTextBuffer)
		endif	
	End Function
	Function GetWindowText OverLoad(byval hwnd as HWND, byval buf as any ptr, byval lenBuf as integer) as Integer Export	
		Return SendMessage(hwnd,WM_GETTEXT,lenBuf,Cast(LParam,buf))
	End Function
#EndIf
