Jump to content

SciLexer UDF


Kip
 Share

Recommended Posts

You have to use the SCI-funtions like _Sci_GetText (or similar name). GUICtrl... will never work with custom controls

*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

Thanks progandy and kip :unsure: I will try these as soon as i return from school. And sorry for the PM . I badly needed a solution that time.

err i think Sci_GetText($Sci) will be Sci_GetLines($Sci)which however returns a zero every time i evoke it even though there are texts in the control :>

Edited by DarkAngel
Link to comment
Share on other sites

  • 3 months later...

I can't seem to get this working. Even in the examples the control just isn't getting made. o_0; I've tried several different sources of the dll at this point but nothing works. Windows 7 64 bit

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

  • 2 weeks later...

I can't seem to get this working. Even in the examples the control just isn't getting made. o_0; I've tried several different sources of the dll at this point but nothing works. Windows 7 64 bit

The DLL is 32 bit. If you are compiling your script in 64-bit mode, it won't work.

Link to comment
Share on other sites

Well ok, I thought that was the problem but I was unable to find a 64bit version earlier. however I managed to hit the magical search string in google and came across a forum post with a link to another forum post with a custom modified version for 64bit, just tested and it seems to be working :mellow:. The file can be found here:

http://scintillanet.codeplex.com/workitem/9977?ProjectName=scintillanet

click on Scintilla176_Custom.zip

Its in the bin_64 folder.

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

  • 11 months later...

Excellent work! Thanks for yourhard work!

Does any one know how to use Sci_FindText (int searchflags, Sci_TextToFind *ttf) ? (Here : http://www.scintilla.org/ScintillaDoc.html )

I've been trying for hours to understand how it works but could'nt even get close to something working!

Any help would be greatly appreciated!

Link to comment
Share on other sites

First parameter should be one of the flag

SCFIND_MATCHCASE - A match only occurs with text that matches the case of the search string.

SCFIND_WHOLEWORD - A match only occurs if the characters before and after are not word characters.

SCFIND_WORDSTART - A match only occurs if the character before is not a word character.

SCFIND_REGEXP - The search string should be interpreted as a regular expression.

SCFIND_POSIX - Treat regular expression in a more POSIX compatible manner by interpreting bare ( and ) for tagged sections rather than ( and ).

For example: if the flag is SCFIND_MATCHCASE then the second parameter is the text you want to find or if the flag is SCFIND_REGEXP then the second parameter it's a regular expression.

I hope it's more clear now.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

Thank you for your quick answer.

It doesn't seem to work. This is how I tried it:

$ret = dllcall ("user32.dll", "int" , "sendMessageA", "hwnd", $Sci , "int" , $Sci_FindText, "int", $ScFind_RegExp, "str", "[a_z]*")

In the help file it is said that it has to be a structure:

struct Sci_TextToFind {
     struct Sci_CharacterRange chrg; // range to search
     char *lpstrText; // the search pattern (zero terminated)
     struct Sci_CharacterRange chrgText; // returned as position of matching text
};

And I have no idea how to do the structure!

Thanks.

Edited by jmon
Link to comment
Share on other sites

Sorry, you're right. Then should be something like this:

$sPattern = "[a_z]*"
$Sci_FindText = DllStructCreate("long cpMin; long cpMax;char lpstrText[" & StringLen($sPattern) + 1 & "];long cpMin; long cpMax;")

;$cpMin and $cpMax should be the range of text to search
DllStructSetData($Sci_FindText,"cpMin",$cpMin)
DllStructSetData($Sci_FindText,"cpMin",$cpMax)

DllStructSetData($Sci_FindText,"lpstrText",$sPattern)

;And the call:
$ret = dllcall ("user32.dll", "int" , "sendMessageA", "hwnd", $Sci , "int" , $Sci_FindText, "int", $ScFind_RegExp, "ptr", DllStructGetPtr($Sci_FindText))

;The result in case of matching
; here $cpMin and $cpMax is position of matching text
$cpMin = DllStructGetData($Sci_FindText,4)
$cpMax = DllStructGetData($Sci_FindText,5)
Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

I still can't get it to work...

here is an example (what I am trying in this example is to find the numbers):

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Add_Constants=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <_SciLexer.au3>

Opt("GUIOnEventMode", 1)

Global $GUI = GUICreate("Test SCI_FINDTEXT", 600, 600)
Global $SCI = Sci_CreateEditor($GUI, 0, 0, 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $GUI)
GUISetState()


While 1
    SciAppendText($SCI, @TAB & "-Random Text:" & @CRLF & _RandomMessage() & @CRLF & @CRLF)
    Sleep(1000)
WEnd

Func _Exit()
    DllClose($user32)
    DllClose($kernel32)
    Exit
EndFunc ;==>_Exit

Func _RandomMessage()
    Local $aMsg[5] = [" C:thisIsATestFolder" & @CRLF & "this is another line", _
            "Hey check out this link: X:Tempfolderautoit.ini another text (123456)" & @CRLF & "And a second line with a linefeed ...." & @CRLF & "And a third line.", _
            "1234 8987 4: X:Tempfolderautoit.ini! ", _
            "Testing some weird characters and other languages: " & Chr("174") & Chr("181") & Chr("190") & Chr("201") & Chr("223"), _
            "Testing a very long line, containing a lot of characters, just to see how scintilla handles it and these are other words to make the sentence evn longer...."]
    Return $aMsg[Random(0, 4, 1)]
EndFunc ;==>_RandomMessage

Func SciAppendText($hwnd, $text)

    SendMessageString($hwnd, $SCI_APPENDTEXT, StringLen($text), $text) ;Append the Text

    Local $iTextLen = SendMessage($SCI, $SCI_GETLENGTH, 0, 0)

    ;HERE : Trying to find the numbers in the randomly appended text:
    Local $sPattern = "[1-9]*"
    Local $SCI_FINDTEXT_Struct = DllStructCreate("long cpMin;long cpMax;char lpstrText[" & StringLen($sPattern) + 1 & "];long cpMin;long cpMax;")

    DllStructSetData($SCI_FINDTEXT_Struct, "cpMin", 0)
    DllStructSetData($SCI_FINDTEXT_Struct, "cpMax", $iTextLen)
    DllStructSetData($SCI_FINDTEXT_Struct, "lpstrText", $sPattern)

    DllCall($user32, "int", "SendMessageA", "hwnd", $hwnd, "int", $SCI_FINDTEXT, "int", $SCFIND_REGEXP, "ptr", DllStructGetPtr($SCI_FINDTEXT_Struct))
    Local $cpMin = DllStructGetData($SCI_FINDTEXT_Struct, 4)
    Local $cpMax = DllStructGetData($SCI_FINDTEXT_Struct, 5)

    ConsoleWrite("$cpMin = " & $cpMin & " $cpMax = " & $cpMax & @CRLF)

EndFunc ;==>SciAppendText

the whole thing crashes after appending the first line. any idea?

[EDIT1]

After further testing, the crash appears at the DLLcall.

Autoit crashes, and returns :

AutoIT3.exe ended.src:-1073741819
Edited by jmon
Link to comment
Share on other sites

Thank you Andreik for your help. the example you gave me helped me a lot in understanding how the structures work. But so far I haven't been able to find anything that works. I have tried so many combinations, but no luck. I'm still trying to get the function to work.

the function I am trying to port to AutoIt is :

SCI_GETTEXTRANGE (<unused>, Sci_TextRange *tr)
This collects the text between the positions cpMin and cpMax and copies it to lpstrText (see struct Sci_TextRange in Scintilla.h). If cpMax is -1, text is returned to the end of the document. The text is 0 terminated, so you must supply a buffer that is at least 1 character longer than the number of characters you wish to read. The return value is the length of the returned text not including the terminating 0.

Sci_TextRange is a structure that needs to be defined like this:

struct Sci_CharacterRange {
long cpMin;
long cpMax;
};

struct Sci_TextRange {
struct Sci_CharacterRange chrg;
char *lpstrText;
};

I have tried to do it but still can't get it working. Anybody have any idea of what is wrong in my code ? I think that would be a great function to add to this UDF, and very usefull to retrieve the text on notification SCN_HOTSPOTCLICK. Another function very interesting is SCI_FINDTEXT, that uses almost the same structure as SCI_TEXTRANGE.

Here is a simple (NEW) test I did to see if the structure is working correctly:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <_SciLexer.au3>
Opt("GUIOnEventMode", 1)


Global $GUI = GUICreate("Test", 600, 600)
Global $SCI = Sci_CreateEditor($GUI, 0, 0, 600, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $GUI)
GUISetState()

;Put some text in the control:
SciAppendText($SCI, 'This is the text. The word I am trying to get is "This"')

;Here, trying to get some text between char 1 and 5:
Global $sTextFromRange = Sci_GetTextRange($SCI, 1, 5)
MsgBox(0, "The text in Range", "The Return = " & $sTextFromRange)


While 1
Sleep(250)
WEnd

Func _Exit()
Exit
EndFunc ;==>_Exit


Func Sci_GetTextRange($hWnd, $cpMin, $cpMax)
;Struct Sci_CharacterRange :
Local $Struct_Sci_CharacterRange = DllStructCreate("long cpMin;long cpMax;")
DllStructSetData($Struct_Sci_CharacterRange, "cpMin", $cpMin)
DllStructSetData($Struct_Sci_CharacterRange, "cpMax", $cpMax)

;Struct Sci_TextRange:
Local $Struct_Sci_TextRange = DllStructCreate("ptr chrg;char lpstrText[" & $cpMax - $cpMin + 1 & "];")
DllStructSetData($Struct_Sci_TextRange, "chrg", DllStructGetPtr($Struct_Sci_CharacterRange))

DllCall("user32.dll", "int", "SendMessageA", "hwnd", $hWnd, "int", $SCI_GETTEXTRANGE, "int", 0, "ptr", DllStructGetPtr($Struct_Sci_TextRange))

Local $Ret = DllStructGetData($Struct_Sci_TextRange, 2)

Return $Ret
EndFunc ;==>Sci_GetTextRange

Func SciAppendText($hWnd, $sText)
SendMessageString($hWnd, $SCI_APPENDTEXT, StringLen($sText), $sText) ;Append the Text
EndFunc ;==>SciAppendText

[EDIT1]

So far the function returns nothing, but if I add " * " (star) to lpstrText ( *lpstrText ) it returns 0.

Do I need the star? what does the star means in the help of scintilla?

Edited by jmon
Link to comment
Share on other sites

  • 2 weeks later...

I have converted THIS example to autoit, hope it helps someone. It is an example to color lines based on first character of the line (like the console in Scite):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <_SciLexer.au3>

Opt("GUIOnEventMode", 1)

;Create some constants for styling:
Global $SCE_STYLE_BLACK = 10
Global $SCE_STYLE_ORANGE = 11
Global $SCE_STYLE_PURPLE = 12
Global $SCE_STYLE_BLUE = 13
Global $SCE_STYLE_DIFBGCOLOR = 14

;Colors (Scilexer uses BGR colors):
Global $black = 0x000000
Global $white = 0xFFFFFF
Global $blue = 0xFF0000
Global $purple = 0x94005E
Global $orange = 0x00A8FF

;Create a Gui:
Global $GUI = GUICreate("Test coloring lines of text", 600, 600)
Global $SCI = Sci_CreateEditor($GUI, 0, 0, 600, 400)
Global $INPUT = GUICtrlCreateInput("", 0, 420, 600, 170)
GUICtrlSetState($INPUT, $GUI_FOCUS)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $GUI)
$DUMMYSEND = GUICtrlCreateDummy()
GUICtrlSetOnEvent($DUMMYSEND, "_Send")
Global $AccelKeys[1][2] = [["{ENTER}", $DUMMYSEND]]
GUISetAccelerators($AccelKeys)
GUISetState()

;Register MY_WM_NOTIFY because WM_NOTIFY is already registered in _SciLexer.au3
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

;Set Lexer Type:
SendMessage($SCI, $SCI_SETLEXER, $SCLEX_CONTAINER, 0)

;Set the default colors and such:
SendMessage($SCI, $SCI_STYLESETFORE, $STYLE_DEFAULT, $black) ;Default FG color
SendMessage($SCI, $SCI_STYLESETBACK, $STYLE_DEFAULT, $white) ;Default BG color
SendMessage($SCI, $SCI_STYLECLEARALL, 0, 0) ;Reset the styles to the default
;Set the colors for our styling types: (here we only define what will be different from the default style)
SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_BLACK, $black)
SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_ORANGE, $orange)
SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_PURPLE, $purple)
SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_BLUE, $blue)
;create one more style which have a different bg color, simple as this:
SendMessage($SCI, $SCI_STYLESETFORE, $SCE_STYLE_DIFBGCOLOR, $white)
SendMessage($SCI, $SCI_STYLESETBACK, $SCE_STYLE_DIFBGCOLOR, $blue)

;append some lines which should be colored according to first character:
SciAppendText($SCI, "/ Purple line because begins with /" & @CRLF)
SciAppendText($SCI, "* Purple line because begins with *" & @CRLF)
SciAppendText($SCI, "- orange line because begins with -" & @CRLF)
SciAppendText($SCI, "black line, uses $SCE_STYLE_BLACK style because not using any defined characters" & @CRLF)
SciAppendText($SCI, "+ this line uses the style $SCE_STYLE_DIFBGCOLOR because begins with +" & @CRLF & @CRLF)
SciAppendText($SCI, "- try to type some other lines" & @CRLF)
SciAppendText($SCI, "- and press [ENTER] to send them." & @CRLF)

While 1
    Sleep(250)
WEnd

Func _Exit()
    Exit
EndFunc ;==>_Exit

Func _Send()
    SciAppendText($SCI, GUICtrlRead($INPUT) & @CRLF)
    GUICtrlSetData($INPUT, "")
EndFunc ;==>_Send

Func MY_WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    Local $tagNMHDR = DllStructCreate("int;int;int;int;int;int;int;ptr;int;int;int;int;int;int;int;int;int;int;int", $lParam)
    $hWndFrom = DllStructGetData($tagNMHDR, 1)
    $IdFrom = DllStructGetData($tagNMHDR, 2)
    $Event = DllStructGetData($tagNMHDR, 3)

    Switch $hWndFrom
        Case $SCI
            Switch $Event
                Case $SCN_STYLENEEDED
                    Local $line_number = SendMessage($SCI, $SCI_LINEFROMPOSITION, SendMessage($SCI, $SCI_GETENDSTYLED, 0, 0), 0)
                    Local $start_pos = SendMessage($SCI, $SCI_POSITIONFROMLINE, $line_number, 0)
                    Local $line_length = SendMessage($SCI, $SCI_LINELENGTH, $line_number, 0)

                    If ($line_length > 0) Then
                        Local $first_char = SendMessage($SCI, $SCI_GETCHARAT, $start_pos, 0)

                        ;The SCI_STARTSTYLING here is important
                        SendMessage($SCI, $SCI_STARTSTYLING, $start_pos, 0x1f)

                        ;Set the colouring based on the first character:
                        Switch Chr($first_char)
                            Case "-"
                                SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_ORANGE)
                            Case "/"
                                SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_PURPLE)
                            Case "*"
                                SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_BLUE)
                            Case "+"
                                SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_DIFBGCOLOR)
                            Case Else
                                SendMessage($SCI, $SCI_SETSTYLING, $line_length, $SCE_STYLE_BLACK)
                        EndSwitch
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>MY_WM_NOTIFY

Func SciAppendText($hwnd, $text)
    SendMessageString($hwnd, $SCI_APPENDTEXT, StringLen($text), $text) ;Append the Text
    Local $iLen = Sci_GetLenght($hwnd)
    SendMessage($hwnd, $SCI_SETANCHOR, $iLen, 0) ;set caret position
    SendMessage($hwnd, $SCI_SETCURRENTPOS, $iLen, 0) ;set caret position
    SendMessage($hwnd, $SCI_SCROLLCARET, 0, 0) ;make caret visible
EndFunc ;==>SciAppendText

Ps: also , if someone can help me with the previous post, I would be very grateful :)

Link to comment
Share on other sites

  • 1 month later...

I have an issue whith sci_appendtext. when I append some non roman characters, like arabic or thai, the characters are converted to question marks.

this problem doesn't happend when I TYPE directly in thai in the window or when I PASTE the text directly in the window.

It seems that somehow the sendmessagestring function is converting the characters?

You can try by copying the arabic characters from the character Map. If anyone could help me with that I would be very grateful.

regards,

Jmon.

Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

I have an issue whith sci_appendtext. when I append some non roman characters, like arabic or thai, the characters are converted to question marks.

this problem doesn't happend when I TYPE directly in thai in the window or when I PASTE the text directly in the window.

It seems that somehow the sendmessagestring function is converting the characters?

You can try by copying the arabic characters from the character Map. If anyone could help me with that I would be very grateful.

regards,

Jmon.

It's because the ANSI version of SendMessage is being used not SendMessageW.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

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...