chenxu Posted April 29, 2009 Share Posted April 29, 2009 (edited) _GUICtrlEdit_SetSel selects some text in a text area, but it does not select the right length of the text in SciTE for AutoIt3 editor, this is the simple script to reproduce this bug, copy the script, paste into your SciTE for AutoIt3 editor, and run the script and you will easily to reproduce this bug with the file result.txt generated by this script in the same fold of this au3 file you savedo make sure the version of your SciTE is >= v1.76expandcollapse popup#Include <GuiEdit.au3> $hWnd = ControlGetHandle("[CLASS:SciTEWindow]", "", 'Scintilla1') For $i = 1 To 500 _GUICtrlEdit_SetSel($hWnd, 0, $i) $len = StringLen(ControlCommand($hWnd, "", "", "GetSelected", "")) ConsoleWrite($i & @TAB & $len & @CRLF) Next ; this following is some text to make this file a litle larger, just ignor the following text ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789oÝ÷ ÚØ^~*ìµÊ%ºiâ²Ø^éබ{^ƶ)à¶ç-{ay'"LNºÚ·wÚ+¶¬yÊ'uÊ%ºiâ²Ø^éබ{ZrÛ¬zWµçbØ^IÈ.¶-Ýçb¶Û¶§ºfÞ®)íërÝrnx¬ë,¶§¶»-rn}ý³öí+"²l¢{(ê.¶jëh×61 1 2 2 3 2 4 3 5 3 6 4 7 4 8 5 9 6 10 6 11 7 12 8 13 8 14 9 15 10 16 10 17 11 18 12 19 13 20 14 21 14 22 15 23 15 24 16 25 17 26 18 27 18 28 19 29 19 30 20 31 20 32 21 33 22 34 22 35 23 36 23 37 24 38 24 39 25 40 25 41 26 42 26 43 27 44 28 45 29 46 29 47 30 48 30 49 31 50 31 Edited April 29, 2009 by chenxu Link to comment Share on other sites More sharing options...
Authenticity Posted April 29, 2009 Share Posted April 29, 2009 Don't know why but I see no unpredictable behavior: #Include <GuiEdit.au3> $hWnd = ControlGetHandle("[CLASS:SciTEWindow]", "", 'Scintilla1') For $i = 1 To StringLen(FileRead(@ScriptFullPath)) _GUICtrlEdit_SetSel($hWnd, 0, $i) Next ; this following is some text to make this file a litle larger, just ignor the following text ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 Link to comment Share on other sites More sharing options...
chenxu Posted April 29, 2009 Author Share Posted April 29, 2009 (edited) try this #Include <GuiEdit.au3> $hWnd = ControlGetHandle("[CLASS:SciTEWindow]", "", 'Scintilla1') For $i = 1 To 500 _GUICtrlEdit_SetSel($hWnd, 0, $i) $len = StringLen(ControlCommand($hWnd, "", "", "GetSelected", "")) ConsoleWrite($i & @TAB & $len & @CRLF) Next Edited April 29, 2009 by chenxu Link to comment Share on other sites More sharing options...
WideBoyDixon Posted April 29, 2009 Share Posted April 29, 2009 The SciTE editor is Unicode. That's why you only get half the characters. Try _GUICtrlEdit_SetSel($hWnd, 0, $i * 2) WBD [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
chenxu Posted April 29, 2009 Author Share Posted April 29, 2009 The SciTE editor is Unicode. That's why you only get half the characters.Try _GUICtrlEdit_SetSel($hWnd, 0, $i * 2)WBDthis doesn't work! _GUICtrlEdit_SetSel does not exactly selects half of the characters Link to comment Share on other sites More sharing options...
Spiff59 Posted April 29, 2009 Share Posted April 29, 2009 Apparently something has been changed between what you're running and what I'm running. For me, Autoit 3.3.0.0 and ScITE 1.77 return a 1-to-1 match for the example in the first post. My console output starts with: 1 1 and ends with: 500 500 Link to comment Share on other sites More sharing options...
99ojo Posted April 29, 2009 Share Posted April 29, 2009 Apparently something has been changed between what you're running and what I'm running.For me, Autoit 3.3.0.0 and ScITE 1.77 return a 1-to-1 match for the example in the first post.My console output starts with:1 1and ends with:500 500Funny,Autoit 3.3.0.0 and ScITE 1.77 returns on my machine not a 1-to1 match for the example in the first post.4 me it is 1to1 until 408 408. The next line is 409 408 and the 408 never changes until 500 ( so last line is 500 408 ).I'm running XP SP3 german version.;-((Stefan Link to comment Share on other sites More sharing options...
Spiff59 Posted April 29, 2009 Share Posted April 29, 2009 (edited) Funny,Autoit 3.3.0.0 and ScITE 1.77 returns on my machine not a 1-to1 match for the example in the first post.4 me it is 1to1 until 408 408. The next line is 409 408 and the 408 never changes until 500 ( so last line is 500 408 ).I'm running XP SP3 german version.;-((StefanAny chance you truncated some of the example when you cut-and-pasted it?If the file is shorter than 500 bytes, then I get the same behavior.Edit: Aha! I'm using a script to grab the example code in post 1. It adds a couple lines of informational comments to the top of the script when capturing. That added a couple hundred more bytes to the example. If I chop those comments out, I get the same results. Hmm, trouble is, there are way more than 500 bytes to begin with. Something is fishy...Edit2: It's still some sort of unicode issue. It reports a 1-to-1 ratio as long as the upper limit of the For/next loop is half the file size or less. Edited April 29, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
Developers Jos Posted April 29, 2009 Developers Share Posted April 29, 2009 (edited) Doubt you can call this a bug because I do not think the SciTE control responds to messages in a standard fashion and it isn't a standard Edit control.. This is an example I've made to read and write to tyhe control: ; ; script to retrieve and set the text in a SciTE Control ; ; *** Retrieve Section $SciTE = '[CLASS:SciTEWindow]' ; Retrieve all text from the SciTE control and convert to Binary Using Unicode $script = StringToBinary(ControlGetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]'),2) ; Translate back to ANSI text $script = BinaryToString($script,1) ; Strip ending 00 plus extra chars $script = string($script) ; Modify text $script &= @crlf & ";testje" ; ; *** Store Section ; ; Translate text to Binary $script = StringToBinary($script,1) ; Add 00 plus stuffing to have a even number of characters needed for UNICODE $script &= StringRight("0000",Mod(StringLen($script),4)+2) ; Translated into UNICODE String $script = BinaryToString($script, 2) ; Set Control text ControlSetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]',$script) Edited April 29, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
chenxu Posted April 30, 2009 Author Share Posted April 30, 2009 Doubt you can call this a bug because I do not think the SciTE control responds to messages in a standard fashion and it isn't a standard Edit control.. This is an example I've made to read and write to tyhe control: ; ; script to retrieve and set the text in a SciTE Control ; ; *** Retrieve Section $SciTE = '[CLASS:SciTEWindow]' ; Retrieve all text from the SciTE control and convert to Binary Using Unicode $script = StringToBinary(ControlGetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]'),2) ; Translate back to ANSI text $script = BinaryToString($script,1) ; Strip ending 00 plus extra chars $script = string($script) ; Modify text $script &= @crlf & ";testje" ; ; *** Store Section ; ; Translate text to Binary $script = StringToBinary($script,1) ; Add 00 plus stuffing to have a even number of characters needed for UNICODE $script &= StringRight("0000",Mod(StringLen($script),4)+2) ; Translated into UNICODE String $script = BinaryToString($script, 2) ; Set Control text ControlSetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]',$script) Thanks a lot for replying, can you tell me how to set the selected text exactly what I need in SciTE editor? Link to comment Share on other sites More sharing options...
Developers Jos Posted April 30, 2009 Developers Share Posted April 30, 2009 Thanks a lot for replying, can you tell me how to set the selected text exactly what I need in SciTE editor?I have been playing with the SciTE director interface but haven't found a way to do any LUA or Scittilla related function that would allow you to do this. I expected the "Extender:" option to make that possible but haven't gotten it to work yet. You can read about it in de SciTE documentation and here is an example of stuff you can do with the Director interface. expandcollapse popup; *** Start added by AutoIt3Wrapper *** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; *** End added by AutoIt3Wrapper *** #Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Add_Constants=n #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** Opt("WinSearchChildren", 1) ;~ Global $WM_COPYDATA = 74 Global $SciTECmd ; Get SciTE DirectorHandle $Scite_hwnd = WinGetHandle("DirectorExtension") ; Get My GUI Handle numeric Global $My_Hwnd = GUICreate("SciTE interface", 300, 600, Default, Default,Default,$WS_EX_TOPMOST) $list = GUICtrlCreateEdit("",1,1,290,590) $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) ;Register COPYDATA message. GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA") GUISetState() ;Send Scite Director my GUI handle so it will report info back from SciTE ;~ SendSciTE_Command($My_Hwnd, $Scite_hwnd, "identity: " & $My_Dec_Hwnd) ;Send Scite Director message to open a file ;~ SendSciTE_Command($My_Hwnd, $SciTE_hwnd,"open:C:\\Development\\winutil\\AutoIt3\\ConvAu32htm\\ConvAu32htm.au3") ;Send Scite Director message to do command ;~ SendSciTE_Command($My_Hwnd, $SciTE_hwnd,"menucommand:1114"); Runs command.14 ;enumproperties:dyn|local|user|base|embed ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"enumproperties:dyn") &@LF) ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"enumproperties:local") &@LF) ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"enumproperties:user") &@LF) ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"enumproperties:base") &@LF) ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"enumproperties:embed") &@LF) ;ConsoleWrite(SendSciTE_GetInfo($My_Hwnd, $SciTE_hwnd,"property:user:find.files=test") &@LF) ; ;AdlibEnable("GetCurrentWord",1000) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Exit ; ; Send command to SciTE Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd) ConsoleWrite('-->' & $sCmd & @lf ) GUICtrlSetData($list,GUICtrlRead($list) & '-->' & $sCmd & @CRLF) Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']') DllStructSetData($CmdStruct, 1, $sCmd) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr') DllStructSetData($COPYDATA, 1, 1) DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1) DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct)) DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _ 'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _ 'Ptr', DllStructGetPtr($COPYDATA)) EndFunc ;==>SendSciTE_Command ; ; ; Received Data from SciTE Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam) Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr',$lparam) $SciTECmdLen = DllStructGetData($COPYDATA, 2) Local $CmdStruct = DllStructCreate('Char[4096]',DllStructGetData($COPYDATA, 3)) $SciTECmd = Stringleft(DllStructGetData($CmdStruct, 1),$SciTECmdLen) ConsoleWrite('<--' & $SciTECmd & @lf ) ;GUICtrlSetData($list,GUICtrlRead($list) & '<--' & $SciTECmd & @CRLF ) EndFunc ;==>MY_WM_COPYDATA ; Func GetCurrentWord() SendSciTE_Command($My_Hwnd, $SciTE_hwnd,"askproperty:CurrentWord") ; Runs command.14 EndFunc ; Func SendSciTE_GetInfo($My_Hwnd, $Scite_hwnd, $sCmd) $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2)) $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd $SciTECmd = "" $SaveSciTECmd = "xxxxx" SendSciTE_Command($My_Hwnd, $SciTE_hwnd,$sCmd) For $x = 1 To 10 If $SciTECmd <> "" Then ExitLoop sleep(20) Next $SciTECmd = StringTrimLeft($SciTECmd,StringLen(":" & $My_Dec_Hwnd & ":")) $SciTECmd = StringReplace($SciTECmd,"macro:stringinfo:","") Return $SciTECmd EndFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Spiff59 Posted May 1, 2009 Share Posted May 1, 2009 (edited) Thanks a lot for replying, can you tell me how to set the selected text exactly what I need in SciTE editor? My understanding of this is... _GUICtrlEdit_SetSel works perfectly. It is the Scintilla GetSelected command that is returning raw unicode data. Correct? I mean, this example is slow, but by replacing the GetSelected it works properly: #Include <GuiEdit.au3> $hWnd = ControlGetHandle("[CLASS:SciTEWindow]", "", 'Scintilla1') For $i = 1 To 500 _GUICtrlEdit_SetSel($hWnd, 0, $i) ; $len = StringLen(ControlCommand($hWnd, "", "", "GetSelected", "")) Send("^c") $len = StringLen(ClipGet()) ConsoleWrite($i & @TAB & $len & @CRLF) Next ; this following is some text to make this file a litle larger, just ignor the following text ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 ;~ 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 Edited May 1, 2009 by Spiff59 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