Jump to content

get script text in SciTE


FireFox
 Share

Recommended Posts

Hi,

I've searched on forum and found nothing...

How can I get the script text in SciTE ?

my script :

$SciTE = '[CLASS:SciTEWindow]'
If Not WinActive($SciTE) Then WinActivate($SciTE)
$script = ControlGetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]')
MsgBox(64, 'ControlGetText', $script)

And $script return value :

?????????????????????????????????????????????????????????????????????????????????]????Z???¤?

Thanks for anyhelp :)

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

You could use clipboard like here: http://www.autoit.de/index.php?page=Thread...35992#post35992

Or you could use this, like my new version of this script (possibly needs admin rights):

; Author: Prog@ndy
#NoTrayIcon
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <Memory.au3>

If Not IsDeclared("WM_COPYDATA") Then Const $WM_COPYDATA = 0x4A
$GUI = Guicreate("Run without saving",200,50,10,10,$WS_CAPTION,$WS_EX_TOPMOST+$WS_EX_TOOLWINDOW )
Global Const $SCI_GETTEXT=2182
If Not ProcessExists('SciTE.exe') Then Exit (0)
; Get SciTE DirectorHandle
$Scite_hwnd = WinGetHandle("DirectorExtension")
GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA")

$text = Sci_GetLines(ControlGethandle("[CLASS:SciTEWindow]","","Scintilla1"))
If @error <> 1 And $text = "" Then
    $My_Dec_Hwnd = Dec(StringTrimLeft($GUI, 2))
    $temp = ClipGet()
    ClipPut('')
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, 'menucommand:207')
    SendSciTE_Command($My_Dec_Hwnd, $Scite_hwnd, 'menucommand:204')
    $text = ClipGet()
    ClipPut($temp)
EndIf

If StringLeft($text,6) = ";#BETA" Or StringInStr($text,"#AutoIt3Wrapper_Version=Beta") Then
    $AutoItExe = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","betaInstallDir") & "\Autoit3.exe"
    $AutoItVers = "Beta: "& RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","betaVersion")
Else
    $AutoItExe = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","InstallDir") & "\Autoit3.exe"
    if $AutoItExe = "\Autoit3.exe" Then $AutoItExe = @AutoItExe
    $AutoItVers = "Stable: "& RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","Version")
EndIf
$File = FileOpen(@TempDir & '\~runnow.au3',2)
FileWrite($File,$text)
FileClose($File)

$btn = GUICtrlCreateButton("STOP (" & $AutoItVers & ")",0,0,200,50)
GUISetState()
ConsoleWrite(">Started Executing without Saving" & @LF)
$startedPID = Run('"' & $AutoItExe & '" ' & '/AutoIt3ExecuteScript "' &@TempDir & '\~runnow.au3"','','',$STDERR_CHILD + $STDOUT_CHILD);Run 
;~ $startedPID = ""
While ProcessExists($startedPID)
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Or $msg = $btn Then
        ProcessClose($startedPID)
        Exit
    EndIf
    If     StdoutRead($startedPID,1) Then ConsoleWrite(StdoutRead($startedPID))
    If     StderrRead($startedPID,1) Then ConsoleWriteError(StderrRead($startedPID))
    Wend
    
Func OnAutoItExit()
    ProcessClose($startedPID)
EndFunc

; from OrganizeIncludes, i think
; Send command to SciTE
Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd)
    $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd
    ;ConsoleWrite('-->' & $sCmd & @LF)
    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

; from OrganizeIncludes, i think
; 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[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
EndFunc   ;==>MY_WM_COPYDATA

Func SendMessage($hwnd, $msg, $wp, $lp)
    Local $ret
    $ret = DllCall("user32.dll", "long", "SendMessageA", "long", $hwnd, "int", $msg, "int", $wp, "int", $lp)
    If @error Then
        SetError(1)
        Return 0
    Else
        SetError(0)
        Return $ret[0]
    EndIf
    
EndFunc   ;==>SendMessage

; I think, i got t from Scilexer UDf from Kip
Func Sci_GetLines($Sci)
    Local $ret, $sText
    $iLen = SendMessage($Sci, $SCI_GETTEXT, 0, 0)
    If @error Then
        Return 0
    EndIf
    If $iLen = 0 Then Return SetError(1,0,"")
    $sBuf = DllStructCreate("byte[" & $iLen & "]")
$proc = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS,1,WinGetProcess($Sci),True)
;~ MsgBox(0, "", _WinAPI_GetLastErrorMessage())
$Mem = _MemVirtualAllocEx($proc,DllStructGetPtr($proc),$iLen,$MEM_COMMIT+$MEM_RESERVE,$PAGE_READWRITE)
    If @error Then
        Return 0
    EndIf
    $ret = DllCall("user32.dll", "long", "SendMessageA", "long", $Sci, "int", $SCI_GETTEXT, "int", $iLen, "ptr", $Mem)
    If @error Then
        Return 0
    EndIf
    Local $iRead
_WinAPI_ReadProcessMemory($proc,$Mem,DllStructGetPtr($sBuf),$iLen,$iRead)
_MemVirtualFreeEx($proc,$Mem,$iLen,$MEM_RELEASE+$MEM_DECOMMIT)
_WinAPI_CloseHandle($proc)
;~ MsgBox(0,"",DllStructGetData($sBuf, 1))
;~  For $i = 1 To $iLen - 1
;~      $sText &= Chr(DllStructGetData($sBuf, 1, $i))
        
$sText = BinaryToString(DllStructGetData($sBuf, 1))
;~  Next
    $sBuf = 0
    If @error Then
        Return 0
    Else
        Return $sText
    EndIf
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Developers

I remember this question was asked before and I know I looked at it briefly then but got it figured out this time :)

$SciTE = '[CLASS:SciTEWindow]'
$script = StringToBinary(ControlGetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]'),2)
$script = BinaryToString($script,1)
ConsoleWrite('Scriptcode: ' & @crlf & $script )
Edited 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

@Jos

When I want to set the text to SciTE, it only write the first character...

How can I do it ? About the same for read ?

Just let me know how to do it like Tidy script, because im doing interessant tool :)

Edit : Just noticed that Tidy isnt in AutoIt...

Cheers, FireFox.

Edited by FireFox
Link to comment
Share on other sites

i think tidy just writes new file and SciTE reloads it, since it has been modified.

Anyway, this func should wordk

#include<WindowsConstants.au3>
#include<WinAPI.au3>
#include<Constants.au3>
#include<Memory.au3>
$SciTE = '[CLASS:SciTEWindow]'
$script = StringToBinary(ControlGetText($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]'),2)
$script = BinaryToString($script,1)
ConsoleWrite('Scriptcode: ' & @crlf & $script )
$testtext = "a test text"

$HWND = ControlGetHandle($SciTE, '', '[CLASS:Scintilla; INSTANCE:1]')

Sci_SetLines($HWND,$testtext)

; Prog@ndy, using code from 
Func Sci_SetLines($Sci,$sText)
    Local Const $SCI_SETTEXT = 2181
    Local $ret
    Local $iLen = StringLen($sText)
;~  $Sci = WinExists($Sci)
;~  If @error Then Return SetError(1,0,0)
    If $iLen = 0 Then Return SetError(1,0,0)
    $sBuf = DllStructCreate("byte[" & $iLen+1 & "]")
    DllStructSetData($sBuf,1,StringToBinary($sText))
    $proc = _WinAPI_OpenProcess(0x28,1,WinGetProcess($Sci),False)
    ;~ MsgBox(0, "", _WinAPI_GetLastErrorMessage())
    $Mem = _MemVirtualAllocEx($proc,DllStructGetPtr($proc),$iLen,$MEM_COMMIT+$MEM_RESERVE,$PAGE_READWRITE)
    If @error Then
        _WinAPI_CloseHandle($proc)
        Return 0
    EndIf
    Local $iWritten
    _WinAPI_WriteProcessMemory($proc,$Mem,DllStructGetPtr($sBuf),$iLen,$iWritten)
    $ret = DllCall("user32.dll", "long", "SendMessageW", "hwnd", $Sci, "int", $SCI_SETTEXT, "int", $iLen, "ptr", $Mem)
    Local $error = @error
    _MemVirtualFreeEx($proc,$Mem,$iLen,$MEM_RELEASE+$MEM_DECOMMIT)
    _WinAPI_CloseHandle($proc)
    If $error Then
        Return 0
    EndIf
    
    Return 1
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Developers

See if this also works for you:

; 
; 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 an 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 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...