arcker Posted February 1, 2007 Share Posted February 1, 2007 (edited) here is my test to create a richedit control i've seen some examples on the forum, but they're too limited and they "only" uses richedit v 2.0 so, after some researches and REALLY limited documentation on richedit 4.1, it seems to work please test this first try and some function edit : you must have the last version of AutoIt3Lib from PaulIA included : - append text (THE solution, works with normal edit too, and no flickering ) - find some text (doesn't work for now) - limit text to specified limit - setpassword (doesn't work, and i don't understand why) - set read only on/off - get selected text (work, but just get the first character of the selection :/) - select random text (demonstration of the SETSEL function) - get line count - get text lenght ps : sry i can't post any images (file bigger than space available bug) expandcollapse popup;create richedit control v4.1 ;By arcker $library = _API_LoadLibrary ("MSFTEDIT.DLL") ;load the library for the 4.1 version (it's good to know) ConsoleWrite($library & @CRLF) $RichEditClass = "RichEdit50W" ;Name of the 4.1 Rich Edit Control #include<A3lWinApi.au3> #include<Guiconstants.au3> #include<guiedit.au3> ;some constants Global Const $EM_AUTOURLDETECT = $WM_USER + 91 Global Const $EM_FINDTEXT = $WM_USER + 56 Global Const $EM_GETLINE = 0xC4 ;global Const $EM_GETLINECOUNT = 0xBA ;Const $EM_GETSEL = 0xB0 Const $EM_GETSELTEXT = $WM_USER + 62 Const $EM_GETTEXTEX = $WM_USER + 94 Const $EM_GETTEXTLENGTHEX = $WM_USER + 95 Const $EM_GETTEXTMODE = $WM_USER + 90 Const $EM_GETTEXTRANGE = $WM_USER + 75 Const $EM_GETSCROLLPOS = $WM_USER + 221 Const $EM_LIMITTEXT = 0xC5 Const $EM_SETPASSWORDCHAR = 0xCC ;Const $EM_SETSEL = 0xB1 ;Const $EM_SETREADONLY = 0xCF Dim $toggle = 0 ;Const $EM_GETLINECOUNT = 0xBA ;the gui ;_API_CloseHandle($library) $handle = GUICreate("test", 500, 500) ;the rich edit control $richedit = _API_CreateWindowEx (0, $RichEditClass, "", BitOR($WS_CHILD, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_HSCROLL, $WS_VSCROLL, $WS_VISIBLE, $ES_MULTILINE), 0, 0, 400, 400, $handle) $findbutton = GUICtrlCreateButton("Find", 420, 20, 60) $addbutton = GUICtrlCreateButton("Add Text", 420, 50, 60) $gettext = GUICtrlCreateButton("Get Sel Text", 410, 80, 80) $getlinecount = GUICtrlCreateButton("Get Line Count", 410, 110, 80) $getscrollpos = GUICtrlCreateButton("Get Scroll Pos", 410, 140, 80) $limittext = GUICtrlCreateButton("Limit text", 410, 170, 80) $setpassword = GUICtrlCreateButton("Set password", 410, 200, 80) $setreadonly = GUICtrlCreateButton("Set Read Only", 410, 230, 80) $randomselect = GUICtrlCreateButton("Random Select", 410, 260, 80) ;GUIRegisterMsg($WM_COMMAND,"WM_NOTIFY") ;sleep(1000) GUISetState(@SW_SHOW) ;_API_SendMessage($richedit,$EM_AUTOURLDETECT,0,0) For $i = 0 To 1 _addtext() Next While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $findbutton _findtext() Case $addbutton _addtext() Case $gettext _getseltext() Case $getlinecount _getlinecount() Case $getscrollpos _getscrollpos() Case $limittext _limittext() Case $setpassword _setpasswordchar() Case $setreadonly _setreadonly() case $randomselect _randomselect() EndSwitch Sleep(10) WEnd Func _exit() Exit EndFunc ;==>_exit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $tNMHDR, $hFrom, $iID, $iCode $tNMHDR = __tagNMHDR ($ilParam) $hFrom = _tagGetData ($tNMHDR, "hWndFrom") $iID = _tagGetData ($tNMHDR, "IDFrom") $iCode = _tagGetData ($tNMHDR, "Code") ConsoleWrite($hFrom & @CRLF) ConsoleWrite($iID & @CRLF) ConsoleWrite($iCode & @CRLF) EndFunc ;==>WM_NOTIFY Func _addtext() $textlengh = _API_SendMessage ($richedit, $WM_GETTEXTLENGTH, 0, 0); ConsoleWrite("textlengh " & $textlengh & @CRLF) $EM_EXSETSEL = $WM_USER + 55 ;ConsoleWrite($EM_SETSEL) ;$EM_REPLACESEL = $WM_USER + 18 _API_SendMessage ($richedit, $EM_SETSEL, $textlengh, $textlengh); ;ConsoleWrite(_API_SendMessage($richedit,$EM_GETSEL, 0,0)); _GUICtrlEditReplaceSel($richedit, 1, "essai " & $textlengh & @CRLF); EndFunc ;==>_addtext Func _findtext() $find = InputBox("Find", "") $findtext = __tagFINDTEXT() $CHARRANGE = __tagCHARRANGE() _tagsetdata ($CHARRANGE, "cbMin", 0) _tagsetdata ($CHARRANGE, "cbMax", 0) _tagsetdata ($findtext, "lpstrText", $find) _tagsetdata ($findtext, "CHARRANGE", _taggetptr ($CHARRANGE)) ConsoleWrite(_API_SendMessage ($richedit, $EM_FINDTEXT, True, 0)) EndFunc ;==>_findtext Func _getseltext() Local $icount $tData = _tagCHARARRAY (4096) $pText = _tagGetPtr ($tData, 1) _tagSetData ($tData, 1, $pText) $return = _API_SendMessage ($richedit, $EM_GETSELTEXT, 0, $pText) $iText = _tagGetData ($tData, 1) MsgBox(0, $return & " Characters copied", $iText, 3) EndFunc ;==>_getseltext Func _getlinecount() $return = _API_SendMessage ($richedit, $EM_GETLINECOUNT, 0, 0) MsgBox(0, "Number of lines", $return, 3) EndFunc ;==>_getlinecount Func _limittext() $number = InputBox("Limit text to N characters", "Enter the limit " & _ "and try to insert more characters" & @CRLF & "Be careful of the empty lines (cost one character)") If Not @error Then _API_SendMessage ($richedit, $EM_LIMITTEXT, $number, 0) EndFunc ;==>_limittext Func _setpasswordchar() ConsoleWrite("set password X" & @CRLF) _API_SendMessage ($richedit, $EM_SETPASSWORDCHAR, "X", 0) EndFunc ;==>_setpasswordchar Func _getscrollpos() $tPoint = __tagPOINT () $pPoint = _tagGetPtr ($tPoint) $return = _API_SendMessage ($richedit, $EM_GETSCROLLPOS, 0, $pPoint) MsgBox(0, "Get scroll pos", "x : " & _tagGetData ($tPoint, "X") & @CRLF & "y : " & _tagGetData ($tPoint, "Y"), 3) EndFunc ;==>_getscrollpos Func _setreadonly() If $toggle = 0 Then $return = _API_SendMessage ($richedit, $EM_SETREADONLY, True, 0) $toggle = 1 GUICtrlSetData($setreadonly, "Read Only ON") Else $return = _API_SendMessage ($richedit, $EM_SETREADONLY, 0, 0) GUICtrlSetData($setreadonly, "Read Only OFF") $toggle = 0 EndIf EndFunc ;==>_setreadonly Func _randomselect() $textlengh = _API_SendMessage ($richedit, $WM_GETTEXTLENGTH, 0, 0) $min = Random(0, $textlengh, 1) $max = Random($min, $textlengh, 1) $textlengh = _API_SendMessage ($richedit, $EM_SETSEL, $min, $max) EndFunc ;==>_randomselect Func __tagCHARRANGE($pPointer = 0) Local $sStruct = "uint;uint" Local $aTag[2] = ["tagCHARRANGE_", __tagStruct ($sStruct, $pPointer) ] Return __tagBuild ($aTag, "cpMin,cpMax") EndFunc ;==>__tagCHARRANGE Func __tagFINDTEXT($pPointer = 0) Local $sStruct = "ptr;str" Local $aTag[2] = ["tagFINDTEXT_", __tagStruct ($sStruct, $pPointer) ] Return __tagBuild ($aTag, "CHARRANGE,lpstrText") EndFunc ;==>__tagFINDTEXT Edited February 1, 2007 by arcker -- Arck System _ Soon -- Ideas make everything "La critique est facile, l'art est difficile" Projects :[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now