#include once "window9.bi"

Function GetSelectTextEditorGadget(ByVal gadget As long) As USTRING Export
	dim as USTRING sRet
	Dim As CHARRANGE range
	Dim As Integer iLineBegin,iLineEnd
	Dim As HWND hw=GadgetID(gadget)
	SendMessage(hw, EM_EXGETSEL, 0, Cast(LPARAM, @range))
	iLineBegin = LineFromCharEditor(gadget)
	iLineEnd = LineFromCharEditor(gadget,range.cpMax)
	sRet = GetGadgetText(gadget)
	sRet = Mid(sRet,range.cpMin+1+iLineBegin,(range.cpMax-range.cpMin) + (iLineEnd-iLineBegin))
	return sRet
End Function
