#include once "window9.bi"

LoadLibrary "RICHED20.DLL"

Function EditorGadget(ByVal gadget As Long, _
					ByVal x As long, ByVal y As Long, _
					ByVal w As Long, ByVal h As long, _
					ByRef sText As USTRING, _
					ByVal style As Long,_
					ByVal tag as long = 0) As HWND Export
	#ifdef UNICODE
		Var hWin = CreateWindowEx(&h00000200, "RICHEDIT20W", *sText, &h503110C4 Or style, x,y,w,h, Cast(HWND,win9GetCurrent()), Cast(HMENU,CInt(gadget)), 0, 0)
	#else	
		Var hWin = CreateWindowEx(&h00000200, "RICHEDIT20A", sText, &h503110C4 Or style, x,y,w,h, Cast(HWND,win9GetCurrent()), Cast(HMENU,CInt(gadget)), 0, 0)
	#EndIf 
	SendMessage(hWin, EM_LIMITTEXT,-1,0)
	win9AddNewGadget (gadget,hWin)
    dim as hwnd hwParent = Cast(HWND,win9GetCurrent())
    for i as Long = 0 to 1000
        dim as USTRING sz = getclassname_(hwParent)
        if instr(sz , "CLASSCLASS_") andalso getparent(hwParent) = 0 then
            if getprop(hwParent , "tabstopenable") then
                win9AddTabStop(hwParent , gadget)
            EndIf
            exit for
        else
            hwParent = getparent(hwParent)
            if hwParent = 0 then exit for
        EndIf
    Next
	win9AddColor(hWin,GetSysColor(COLOR_WINDOW),GetSysColor(COLOR_WINDOWTEXT))
	If win9GetGadgetFont()<>0 Then SendMessage(hWin, WM_SETFONT, win9GetGadgetFont(),0)
	Return hWin
End Function
