Jump to content

Scintilla DLL with AUtoIT?


Recommended Posts

Hi there, does someone want to help me with this little project?

I want to use Scintilla DLL in AutoIT to make a very simple syntax highlighter.

Don't know if that's possible but I assume it is because AutoIT can load dll's.

What I want to make is a syntax highlighter as simple a possible, a small menu (just save as and other basic stuff)

and only the words true and false in another color.

Its for learning purposes so that I can first make this small steps and then modify the code for making it more complicated.

I thank you in advance  :)

 

TheAutomator.
Link to comment
Share on other sites

I'm sure there will be many people willing to help.

But very few without seeing your code.

 

John,

If wish I had some more advanced code because I didn't get much further than using the standard edit..

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


$Form1 = GUICreate("ScriptEditor", 381, 221, 436, 212)
$MenuItem2 = GUICtrlCreateMenu("File")
$MenuItem5 = GUICtrlCreateMenuItem("Save", $MenuItem2)
$MenuItem4 = GUICtrlCreateMenuItem("Save As", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenuItem("Close", $MenuItem2)
$MenuItem1 = GUICtrlCreateMenu("Help")
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem1)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 380, 200)
GUICtrlSetData(-1, "Edit1")
GUICtrlSetFont(-1, 9, 800, 0, "Lucida Console")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x464646)
GUICtrlSetCursor (-1, 5)
GUISetState(@SW_SHOW)

DllOpen ( "Scintilla.DLL" ) ;stuck...

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

what I need is a starting point  :unsure:

I know how to load the dll but there it stops, I don't know what I should do next..

sorry for the newbieness  :P

i'm a beginner with dll's...

TheAutomator. 

Edited by TheAutomator
Link to comment
Share on other sites

You might want to search for ISN studio in the Examples section, I believe that uses the Scintilla editor for its main editing screen.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Ok guys, I try'd to study "ScriptEditor 1.7 - Forums Release" and "ISN AutoIt Studio" but wow,

that's not simple!

The files from ScriptEditor 1.7 don't even contain a call to the SciLexer.dll and the rest of the code is Chinese for me..

also the 'AU3' scripts in the folder with it won't work because they can't find some UDF include-files that are missing...

Same with ISN AutoIt Studio source code, comment is written in German and also a lot of code for a newbie to even understand..

I tried my best but it's a little bit to advanced for now, what I need is just a simple peace of small code that shows me how to use the SciLexer.dll with a few lines of code..

 

Thanks for the support already!

TheAutomator.

Link to comment
Share on other sites

DLL calls are not for new users, they're generally for the advanced programmers.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

 

but wow,

that's not simple!

 

Life is not easy but simply brutal. 
You have to devote your time to gain knowledge. 
But at least you have a starting point, access to knowledge, initiative, and eventually you can always ask questions here in the forum. 
 
I greet 
mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

BrewManNH,

DLL calls are not for new users, they're generally for the advanced programmers.

 

 

How would I become an advanced programmer if I never start learning advanced stuff?  ;)

working with the functions of AutoIT are no problem (except for dll calls), i'm not a total beginner but a newbie in dll's...

Some things I learn quicker with a teacher instead of reading a bunch of code that I don't understand  :geek:

That's why I ask for an example here, I scanned the whole forum on SciLexer topics, but most of them are to advanced or with errors in the scripts...

But I appreciate the help and I understand if you don't wan't to teach me all that  :)

Thanks for your time.

mLipok,

Life is not easy but simply brutal. 
You have to devote your time to gain knowledge. 
But at least you have a starting point, access to knowledge, initiative, and eventually you can always ask questions here in the forum. 
 
I devote my time to gain knowledge and I use the internet a lot for my programming problems but sometimes I get lost in all that information  :P 
I'm asking for something like a simple example because I can't find that using the internet..
here is the most simple script I found but I just get a blank window:
(all required files are in the script folder)
#include <GUIConstants.au3>
#include "scintilla.h.au3"
#include <Array.au3>
#include <file.au3>
;#include "find.au3"
#include <Math.au3>
#include <Misc.au3>


Opt("GUIOnEventMode", 1)




#Region ### START Koda GUI section ### Form=AForm1.kxf
$Form1 = GUICreate("LEdit by lokster v0.5 (20070207)", 633, 450, -1, -1, BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_OVERLAPPEDWINDOW,$WS_TILEDWINDOW,$WS_POPUPWINDOW,$WS_GROUP,$WS_TABSTOP,$WS_BORDER,$WS_CLIPSIBLINGS))
$mFile = GUICtrlCreateMenu("&File")
$mFileNew = GUICtrlCreateMenuItem("New (Ctrl+N)", $mFile)
$mFileOpen = GUICtrlCreateMenuItem("Open (Ctrl+O)", $mFile)
$mFileSave = GUICtrlCreateMenuItem("Save (Ctrl+S)", $mFile)
$mFileSaveAs = GUICtrlCreateMenuItem("Save As (Shift+S)", $mFile)
$mSep1 = GUICtrlCreateMenuItem("", $mFile)
$mFileExit = GUICtrlCreateMenuItem("Exit", $mFile)
$mEdit = GUICtrlCreateMenu("&Edit")
$mEditUndo = GUICtrlCreateMenuItem("Undo", $mEdit)
$mEditRedo = GUICtrlCreateMenuItem("Redo", $mEdit)
$mSep2 = GUICtrlCreateMenuItem("", $mEdit)
$mEditCut = GUICtrlCreateMenuItem("Cut", $mEdit)
$mEditCopy = GUICtrlCreateMenuItem("Copy", $mEdit)
$mEditPaste = GUICtrlCreateMenuItem("Paste", $mEdit)
$mEditDelete = GUICtrlCreateMenuItem("Delete", $mEdit)
$mSep3 = GUICtrlCreateMenuItem("", $mEdit)
$mEditSelectAll = GUICtrlCreateMenuItem("Select all", $mEdit)
$MenuItem2 = GUICtrlCreateMenu("&Search")
$mSearchFind = GUICtrlCreateMenuItem("Find / Replace (Ctrl+F)", $MenuItem2)
$mSearchFindNext = GUICtrlCreateMenuItem("Find next (F3)", $MenuItem2)
$mSearchFindPrevious = GUICtrlCreateMenuItem("Find previous (Shift+F3)", $MenuItem2)
$MenuItem5 = GUICtrlCreateMenuItem("", $MenuItem2)
$mSearchGotoLine = GUICtrlCreateMenuItem("Go to line (Ctrl+G)", $MenuItem2)
$mView = GUICtrlCreateMenu("&View")
$mViewLineNumbers = GUICtrlCreateMenuItem("Line numbers", $mView)
$mViewFolds = GUICtrlCreateMenuItem("Folds", $mView)
$mViewWhitespaces = GUICtrlCreateMenuItem("Whitespaces", $mView)
$mHighlighter = GUICtrlCreateMenu("H&ighlighter")
$mHelp = GUICtrlCreateMenu("&Help")
$mHelpAbout = GUICtrlCreateMenuItem("About", $mHelp)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


#Region ### START Koda GUI section ### Form=find.kxf
$fFind1 = GUICreate("Find / Replace", 402, 137, -1, -1, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS,$DS_MODALFRAME), BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Label1 = GUICtrlCreateLabel("Find what:", 8, 12, 53, 17)
$Label2 = GUICtrlCreateLabel("Replace with:", 8, 36, 69, 17)
$Combo1 = GUICtrlCreateCombo("", 80, 8, 193, 25)
$Combo2 = GUICtrlCreateCombo("", 80, 32, 193, 25)
$cbFindWholeWords = GUICtrlCreateCheckbox("Match whole words only", 8, 80, 137, 17)
$cbFindMatchCase = GUICtrlCreateCheckbox("Match case", 8, 96, 81, 17)
$cbFindRe = GUICtrlCreateCheckbox("Regular expression", 8, 64, 113, 17)
$btnFindNext = GUICtrlCreateButton("Find next", 280, 8, 115, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "btnFindNextClick")
$btnFindReplace = GUICtrlCreateButton("Replace", 280, 40, 115, 25, 0)
GUICtrlSetOnEvent(-1, "btnFindReplaceClick")
$btnFindReplaceAll = GUICtrlCreateButton("Replace All", 280, 72, 115, 25, 0)
GUICtrlSetOnEvent(-1, "btnFindReplaceAllClick")
$btnFindClose = GUICtrlCreateButton("Close", 280, 104, 115, 25, 0)
GUICtrlSetOnEvent(-1, "CloseFind")
$Group1 = GUICtrlCreateGroup("Direction", 208, 72, 65, 57)
$rFindDirectionUp = GUICtrlCreateRadio("up", 216, 88, 49, 17)
$rFindDirectionDown = GUICtrlCreateRadio("down", 216, 104, 49, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$cbFindWrapAround = GUICtrlCreateCheckbox("Wrap around", 8, 112, 97, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$cbFindShowWarnings = GUICtrlCreateCheckbox("Show warnings", 104, 112, 97, 17)
#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseFind",$fFind1)


GUISetOnEvent($GUI_EVENT_CLOSE, "Bye",$Form1)
GUISetOnEvent($GUI_EVENT_RESIZED, "FitEditor",$Form1)
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "FitEditor",$Form1)
GUISetOnEvent($GUI_EVENT_RESTORE, "FitEditor",$Form1)


;menu events
;File
GUICtrlSetOnEvent($mFile,"MenuCmd")
GUICtrlSetOnEvent($mFileNew,"MenuCmd")
GUICtrlSetOnEvent($mFileOpen,"MenuCmd")
GUICtrlSetOnEvent($mFileSave,"MenuCmd")
GUICtrlSetOnEvent($mFileSaveAs,"MenuCmd")
GUICtrlSetOnEvent($mFileExit,"MenuCmd")
;Edit
GUICtrlSetOnEvent($mEdit,"MenuCmd")
GUICtrlSetOnEvent($mEditUndo,"MenuCmd")
GUICtrlSetOnEvent($mEditRedo,"MenuCmd")
GUICtrlSetOnEvent($mEditCut,"MenuCmd")
GUICtrlSetOnEvent($mEditCopy,"MenuCmd")
GUICtrlSetOnEvent($mEditPaste,"MenuCmd")
GUICtrlSetOnEvent($mEditDelete,"MenuCmd")
GUICtrlSetOnEvent($mEditSelectAll,"MenuCmd")
;Search
GUICtrlSetOnEvent($mSearchFind,"MenuCmd")
GUICtrlSetOnEvent($mSearchFindNext,"MenuCmd")
GUICtrlSetOnEvent($mSearchFindPrevious,"MenuCmd")
GUICtrlSetOnEvent($mSearchGotoLine,"MenuCmd")
;View
GUICtrlSetOnEvent($mViewLineNumbers,"MenuCmd")
GUICtrlSetOnEvent($mViewFolds,"MenuCmd")
GUICtrlSetOnEvent($mViewWhitespaces,"MenuCmd")


;Help
GUICtrlSetOnEvent($mHelpAbout,"MenuCmd")


global const $MARGIN_SCRIPT_FOLD_INDEX = 1
Global const $appname = "LEdit by lokster (Scintilla example)"


global $sci
global $user32 = DllOpen("user32.dll")
global $kernel32 = DllOpen("kernel32.dll")
global $_FILENAME ;holds the currently opened filename
Global $highlighters
global $highlighters_menu[1]
Global $cmdrun,$cmdbuild,$cmdcompile
Global $_CUR_FIND_POS = 0
;Options
Global $show_line_numbers =False
Global $default_style = "0x000000,0xFFFFFF,10,Courier New,0,0,0"
Global $tab_width = 2
Global $show_folds = False
Global $show_whitespaces = False
;Find
Global $_OPT_FIND_WRAPAROUND = True
Global $findWhat=""
Global $reverseDirection=False
Global $showWarnings=False
Global $flags=0


Func CloseFind()
GUISetState(@SW_HIDE,$fFind1)
EndFunc


Func btnFindNextClick()
Global $sci,$flags,$findWhat,$findTarget,$wrapFind,$reverseDirection
$flags = 0


if GUICtrlRead($cbFindMatchCase)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_MATCHCASE)
EndIf


if GUICtrlRead($cbFindWholeWords)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_WHOLEWORD)
EndIf


if GUICtrlRead($cbFindRe)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_REGEXP,$SCFIND_POSIX)
EndIf


if GUICtrlRead($cbFindWrapAround)==$GUI_CHECKED Then
$wrapFind = True
Else
$wrapFind = False
EndIf




if GUICtrlRead($rFindDirectionUp)==$GUI_CHECKED Then
$reverseDirection = True
Else
$reverseDirection = False
EndIf


if GUICtrlRead($cbFindShowWarnings)==$GUI_CHECKED Then
$showWarnings = True
Else
$showWarnings = False
EndIf


$findWhat = GUICtrlRead($Combo1)
GUICtrlSetData($Combo1,$findWhat,$findWhat)
FindNext(GUICtrlRead($Combo1),$reverseDirection, $showWarnings,$flags)
EndFunc




Func btnFindReplaceAllClick()
Global $sci,$flags,$findWhat,$findTarget,$wrapFind,$reverseDirection
$flags = 0


if GUICtrlRead($cbFindMatchCase)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_MATCHCASE)
EndIf


if GUICtrlRead($cbFindWholeWords)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_WHOLEWORD)
EndIf


if GUICtrlRead($cbFindRe)==$GUI_CHECKED Then
$flags = BitOR($flags,$SCFIND_REGEXP,$SCFIND_POSIX)
EndIf


if GUICtrlRead($cbFindWrapAround)==$GUI_CHECKED Then
$wrapFind = True
Else
$wrapFind = False
EndIf




if GUICtrlRead($rFindDirectionUp)==$GUI_CHECKED Then
$reverseDirection = True
Else
$reverseDirection = False
EndIf


if GUICtrlRead($cbFindShowWarnings)==$GUI_CHECKED Then
$showWarnings = True
Else
$showWarnings = False
EndIf


$findWhat = GUICtrlRead($Combo1)
While FindNext($findWhat,$reverseDirection, $showWarnings,$flags)>-1
SendMessageString($sci,$SCI_REPLACESEL,0,GUICtrlRead($Combo2))
WEnd
EndFunc




Func btnFindReplaceClick()
If GetSelLength($sci)>0 Then
SendMessageString($sci,$SCI_REPLACESEL,0,GUICtrlRead($Combo2))
btnFindNextClick()
EndIf
EndFunc




Func btnFindReplaceInSelClick()


EndFunc


Func NewFile()
if SendMessage($sci, $SCI_GETMODIFY,0,0) <> 0 Then
$ans = MsgBox(3+32,"Confirm","Save changes to file "&$_FILENAME)
switch $ans
case 2 ; cancel
Return
case 6 ;yes
SaveFile($_FILENAME)
case 7 ;no
EndSwitch
EndIf


SendMessage($sci, $SCI_CLEARALL,0,0)
SendMessage($sci, $SCI_EMPTYUNDOBUFFER,0,0)
SendMessage($sci, $SCI_SETSAVEPOINT,0,0)
$_FILENAME = ""
SetWindowTitle()
EndFunc


Func SetWindowTitle()
If $_FILENAME <> "" Then
WinSetTitle($form1,"",$_FILENAME&" - "&$appname)
Else
WinSetTitle($form1,"","New - "&$appname)
EndIf
EndFunc


Func GoToLine()
$line = InputBox("Go to line","Enter line number","","",-1,40)
if StringIsInt ($line) Then
SendMessage($sci,$SCI_ENSUREVISIBLEENFORCEPOLICY, $line,0);
SendMessage($sci,$SCI_GOTOLINE,$line,0)
EndIf
EndFunc


Func IniReadLong($file,$section,$key,$default="")
$handle = FileOpen($file,0)
Local $longline
Local $found = False
while 1
$line = FileReadLine($handle)
if @error = -1 Then
ExitLoop
EndIf


$pos = StringInStr($line,$key&"=",0,1)


if $pos = 1 Then
$found = true
$line = StringReplace($line,$key&"=","",1)
EndIf


if $found Then
if $line = "" Then
ExitLoop
ElseIf StringInStr($line,"\",0,-1)>0 Then
$line = StringTrimRight($line,1)
$longline &= $line
ExitLoop
ElseIf StringInStr($line,"=")>0 Then
ExitLoop
Else
$longline &= $line
EndIf
EndIf


WEnd
FileClose($handle)
if $longline = "" Then
$longline = $default
EndIf
Return $longline
EndFunc


Func SetProperty($sci,$property,$value)
Local $ret
If IsInt($property) Then
$prop_type = "int"
ElseIf IsString($property) Then
$prop_type = "str"
EndIf


If IsInt($value) Then
$val_type = "int"
ElseIf IsString($value) Then
$val_type = "str"
EndIf


$ret = DllCall($user32, "int", "SendMessageA", "hwnd", $sci, "int", $SCI_SETPROPERTY, $prop_type, $property, $val_type, $value) 
Return $ret[0]
EndFunc


Func OpenFile()
if SendMessage($sci, $SCI_GETMODIFY,0,0) <> 0 Then
$ans = MsgBox(3+32,"Confirm","Save changes to file "&$_FILENAME)
switch $ans
case 2 ; cancel
Return
case 6 ;yes
SaveFile($_FILENAME)
EndSwitch
EndIf 


$from = FileOpenDialog("Open file...","","All files (*.*)")
if $from = '' Then
Return
EndIf
$_FILENAME = $from


SendMessage($sci, $SCI_CLEARALL,0,0)
SendMessage($sci, $SCI_EMPTYUNDOBUFFER,0,0)
SendMessage($sci, $SCI_SETSAVEPOINT,0,0)
SendMessage($sci, $SCI_CANCEL,0,0)
SendMessage($sci, $SCI_SETUNDOCOLLECTION,0,0)


DetectHighlighter($_FILENAME)
$file = FileOpen($from,0)
While 1
$buffer = FileRead($file, 1024)
If @error = -1 Then ExitLoop
SendMessageString($sci, $SCI_APPENDTEXT, StringLen($buffer), $buffer)
Wend
FileClose($file)
SendMessage($sci, $SCI_SETUNDOCOLLECTION, 1,0)
SendMessage($sci, $SCI_EMPTYUNDOBUFFER,0,0)
SendMessage($sci, $SCI_SETSAVEPOINT,0,0)
SendMessage($sci, $SCI_GOTOPOS, 0,0)
SetWindowTitle()
EndFunc


Func SaveFile($fn="")
if $fn = '' then 
$fn = FileSaveDialog("Save file...","","All files (*.*)")
EndIf


if $fn <>'' Then
$_FILENAME = $fn
$len = SendMessage($sci,$SCI_GETLENGTH,0,0)
$text = DllStructCreate("char["&$len&"]")
DllCall($user32, "int", "SendMessageA", "hwnd", $sci, "int", $SCI_GETTEXT, "int", $len+1, "ptr", DllStructGetPtr($text))
;MsgBox(0,0,DllStructGetData($text,1))
$handle = FileOpen($_FILENAME,2)
FileWrite($handle,DllStructGetData($text,1))
FileClose($handle)
$text = 0
SendMessageString($sci, $SCI_SETUNDOCOLLECTION, 1,0)
SendMessageString($sci, $SCI_EMPTYUNDOBUFFER,0,0)
SendMessageString($sci, $SCI_SETSAVEPOINT,0,0)
SetWindowTitle()
Return True
Else
Return False
EndIf


EndFunc


Func MenuCmd()
Switch @GUI_CTRLID
case $mFileNew
NewFile()
case $mFileOpen
OpenFile()
case $mFileSave
SaveFile($_FILENAME)
case $mFileSaveAs
SaveFile()
case $mSearchFind
GUISetState(@SW_SHOW,$fFind1)
case $mSearchFindNext
FindNext($findWhat,False, $showWarnings,$flags,False)
Case $mSearchFindPrevious
FindNext($findWhat,True, $showWarnings,$flags,False)
case $mEditUndo
SendMessage($sci,$SCI_UNDO,0,0)
case $mEditRedo
SendMessage($sci,$SCI_REDO,0,0)
case $mEditCut
SendMessage($sci,$SCI_CUT,0,0)
case $mEditCopy
SendMessage($sci,$SCI_COPY,0,0)
case $mEditPaste
SendMessage($sci,$SCI_PASTE,0,0)
case $mEditDelete
SendMessage($sci,$SCI_CLEAR,0,0)
case $mEditSelectAll
SendMessage($sci,$SCI_SELECTALL,0,0)
case $mSearchGotoLine
GoToLine()
case $mViewLineNumbers
$show_line_numbers = not $show_line_numbers
ShowLineNumbers($show_line_numbers)
case $mViewWhitespaces
$show_whitespaces = not $show_whitespaces
ShowWhitespaces($show_whitespaces)
case $mViewFolds
$show_folds = not $show_folds
ShowFolds($show_folds)
case $mHelpAbout
MsgBox(64,"About","Scintilla example by lokster")
case $mFileExit
Bye()
EndSwitch
EndFunc


Func Bye()
if SendMessage($sci, $SCI_GETMODIFY,0,0) <> 0 Then
$ans = MsgBox(3+32,"LEdit","Save changes to file "&$_FILENAME)
switch $ans
case 2 ; cancel
Return
case 6 ;yes
SaveFile($_FILENAME)
case 7 ;no
EndSwitch
EndIf
DllClose($user32)
DllClose($kernel32)
Exit
EndFunc


Func errDllCall($err, $ext, $erl=@ScriptLineNumber)
   Local $ret = 0
   If $err <> 0 Then
      ConsoleWrite("(" & $erl & ") := @error:=" & $err & ", @extended:=" & $ext & @LF)
      $ret = 1
   EndIf
   Return $ret
EndFunc


Func CreateWindowEx($dwExStyle, $lpClassName, $lpWindowName="", $dwStyle=-1, $x=0, $y=0, $nWidth=0, $nHeight=0, $hwndParent=0, $hMenu=0, $hInstance=0, $lParm=0 )
   Local $ret
   If $hInstance=0 Then
      $ret = DLLCall( $user32,"long","GetWindowLong","hwnd",$hwndParent,"int",-6)
      $hInstance = $ret[0]
   EndIf
   $ret =  DllCall($user32, "hwnd", "CreateWindowEx", "long", $dwExStyle, _
            "str", $lpClassName, "str", $lpWindowName, _
            "long", $dwStyle, "int", $x, "int", $y, "int", $nWidth, "int", $nHeight, _
            "hwnd", $hwndParent, "hwnd", $hMenu, "long", $hInstance, "ptr", $lParm)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc


Func LoadLibrary($lpFileName)
   Local $ret
   $ret = DllCall($kernel32, "int", "LoadLibrary", "str", $lpFileName)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc


Func SendMessage($sci,$msg, $wp, $lp)
   Local $ret
   $ret = DllCall($user32, "long", "SendMessageA", "long", $sci, "int", $msg, "int", $wp, "int", $lp)
   Return $ret[0]
EndFunc


Func SendMessageString($sci,$msg, $wp, $str)
   Local $ret
   $ret = DllCall($user32, "int", "SendMessageA", "hwnd", $sci, "int", $msg, "int", $wp, "str", $str)
   Return $ret[0]
EndFunc


Func SetWindowPos($hwnd, $style, $left, $top, $width, $height, $flags)
   Local $ret
   $ret = DllCall($user32, "long", "SetWindowPos", "long", $hwnd, "long", $style, _
   "long", $left, "long", $top, "long", $width, "long", $height, _
   "long", $flags)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc




Func FitEditor()
;MsgBox(0,0,0)
$size = WinGetClientSize($Form1)
;SetWindowPos(GUICtrlGetHandle($Edit1),0,0,$size[1]-100,$size[0],100,0)
    SetWindowPos($sci, 0, 0, 0, $size[0], $size[1], 0)
GUISetState(@SW_SHOW,$Form1)
EndFunc


Func CreateEditor()
    Local $GWL_HINSTANCE = -6
    Local $hLib = LoadLibrary("SciLexer.DLL")


    Local $hInstance = 0
global $sci


    $sci = CreateWindowEx($WS_EX_CLIENTEDGE, "Scintilla", _
            "TEST", BitOR($WS_CHILD, $WS_VISIBLE,$WS_HSCROLL,$WS_VSCROLL, $WS_TABSTOP, $WS_CLIPCHILDREN), 0, 0, 100, 100, _
            $form1, 0, $hInstance, 0)
GUISetState(@SW_SHOW,$Form1)
EndFunc


Func LoadHiglight($file)
if not FileExists($file) Then
MsgBox(16,"Error","The highlighter file "&$file&" does not exist!")
Return
EndIf


$cmdrun = IniRead($file,"","run","")
$cmdbuild = IniRead($file,"","build","")
$cmdcompile = IniRead($file,"","compile","")
SetStyle($STYLE_DEFAULT,IniRead($file,"","DefaultStyle",$default_style))
SendMessageString($sci,$SCI_STYLECLEARALL,0,0)


SendMessageString($sci,$SCI_SETLEXER,IniRead($file,"","lex",0),0)
$bits = SendMessageString($sci,$SCI_GETSTYLEBITSNEEDED,0,0)
SendMessageString($sci,$SCI_SETSTYLEBITS,$bits,0)


$inif = FileRead($file)
$arr = StringRegExp($inif,"(?m)^style([0-9]+)=(.*)",3)
for $i = 0 to UBound($arr)-1 step 2
SetStyle($arr[$i],$arr[$i+1])
Next


$arr = StringRegExp($inif,"(?m)(?s)(?U)^words([0-9]+)=(.*)\r\n\r\n",3)
for $i = 0 to UBound($arr)-1 step 2
SendMessageString($sci,$SCI_SETKEYWORDS,$arr[$i],$arr[$i+1])
Next
EndFunc


Func InitEditor()
SetStyle($STYLE_DEFAULT,$default_style)
ListHighlighters()
ShowLineNumbers($show_line_numbers) 
SendMessage($sci,$SCI_SETTABWIDTH,$tab_width,0)
ShowWhitespaces($show_whitespaces)
SetProperty($sci,"fold", "1")
SetProperty($sci,"fold.compact", "1")
SetProperty($sci,"fold.comment", "1")
SetProperty($sci,"fold.preprocessor", "1")
SendMessageString($sci,$SCI_SETBUFFEREDDRAW, 1, 0); buffered drawing of the text
;setup folds margin
SendMessage($sci,$SCI_SETMARGINTYPEN, $MARGIN_SCRIPT_FOLD_INDEX, $SC_MARGIN_SYMBOL)
SendMessage($sci,$SCI_SETMARGINMASKN, $MARGIN_SCRIPT_FOLD_INDEX, $SC_MASK_FOLDERS)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDER, $SC_MARK_PLUS)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPEN, $SC_MARK_MINUS)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEREND, $SC_MARK_EMPTY)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERMIDTAIL, $SC_MARK_EMPTY)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPENMID, $SC_MARK_EMPTY)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERSUB, $SC_MARK_EMPTY)
SendMessage($sci,$SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERTAIL, $SC_MARK_EMPTY)
SendMessage($sci,$SCI_SETFOLDFLAGS, 16, 0)
SendMessage($sci,$SCI_SETMARGINSENSITIVEN, 1, 1)
ShowFolds($show_folds)
;----
ClearCmdKey($sci,0x47,$SCMOD_CTRL);unbind the default ctrl+g action
ClearCmdKey($sci,0x4E,$SCMOD_CTRL);unbind the default ctrl+n action
ClearCmdKey($sci,0x4F,$SCMOD_CTRL);unbind the default ctrl+o action
ClearCmdKey($sci,0x53,$SCMOD_CTRL);unbind the default ctrl+s action
ClearCmdKey($sci,0x46,$SCMOD_CTRL);unbind the default ctrl+f action
ClearCmdKey($sci,0x53,$SCMOD_SHIFT);unbind the default shift+s action
ClearCmdKey($sci,0x46,$SCMOD_SHIFT);unbind the default shift+f action
GUIRegisterMsg(0x004E,"WM_NOTIFY") ;WM_NOTIFY
EndFunc


Func ClearCmdKey($sci,$keycode,$modifier=0)
Return SendMessage($sci,$SCI_CLEARCMDKEY, BitShift($modifier,-16)+$keycode, 0);
EndFunc


Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    ;$tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
$tagNMHDR = DllStructCreate("int;int;int;int;int;int;int;ptr;int;int;int;int;int;int;int;int;int;int;int",$lParam)
    If @error Then Return


    $hwndFrom = DllStructGetData($tagNMHDR, 1)
    $idFrom = DllStructGetData($tagNMHDR, 2)
    $event = DllStructGetData($tagNMHDR, 3)
$position = DllStructGetData($tagNMHDR, 4)
$ch = DllStructGetData($tagNMHDR, 5)
$modifiers = DllStructGetData($tagNMHDR, 6)
$modificationType = DllStructGetData($tagNMHDR, 7)
$char = DllStructGetData($tagNMHDR, 8)
$length = DllStructGetData($tagNMHDR, 9)
$linesAdded = DllStructGetData($tagNMHDR, 10)
$message = DllStructGetData($tagNMHDR, 11)
$uptr_t = DllStructGetData($tagNMHDR, 12)
$sptr_t = DllStructGetData($tagNMHDR, 13)
$line = DllStructGetData($tagNMHDR, 14)
$foldLevelNow = DllStructGetData($tagNMHDR, 15)
$foldLevelPrev = DllStructGetData($tagNMHDR, 16)
$margin = DllStructGetData($tagNMHDR, 17)
$listType = DllStructGetData($tagNMHDR,18)
$x = DllStructGetData($tagNMHDR, 19)
$y = DllStructGetData($tagNMHDR, 20)
$line_number = SendMessage($sci,$SCI_LINEFROMPOSITION, $position, 0)
    Select
Case $hwndFrom = $sci
            Select
                Case $event = $SCN_MARGINCLICK
SendMessage($sci,$SCI_TOGGLEFOLD, $line_number, 0)
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
    Return $GUI_RUNDEFMSG 
EndFunc




Func FindInTarget($findWhat, $lenFind, $startPosition, $endPosition)
Global $findTarget;


SendMessage($sci,$SCI_SETTARGETSTART, $startPosition,0)
SendMessage($sci,$SCI_SETTARGETEND, $endPosition,0)


$findWhatPtr = DllStructCreate("char["&StringLen($findWhat)+1&"]")
DllStructSetData($findWhatPtr,1,$findWhat)
$ret = DllCall($user32, "int", "SendMessageA", "hwnd", $sci, "int", $SCI_SEARCHINTARGET, "int", StringLen($findWhat), "ptr", DllStructGetPtr($findWhatPtr))
$posFind = $ret[0]
ConsoleWrite("$posFind1="&$posFind&@CR)




$findWhatPtr = 0
return $posFind;
EndFunc


Func WarnUser($txt)
Return MsgBox(262144+8192,"Warning",$txt)
EndFunc


Func EnsureRangeVisible($posStart, $posEnd, $enforcePolicy=False)
$lineStart = SendMessage($sci,$SCI_LINEFROMPOSITION,  _Min($posStart, $posEnd),0);
$lineEnd = SendMessage($sci,$SCI_LINEFROMPOSITION, _Max($posStart, $posEnd),0);
for $line = $lineStart To $lineEnd
If ($enforcePolicy) Then
SendMessage($sci,$SCI_ENSUREVISIBLEENFORCEPOLICY,$line,0)
Else
SendMessage($sci,$SCI_ENSUREVISIBLE,$line,0)


EndIf
Next
EndFunc


Func SetSelection($anchor, $currentPos)
SendMessage($sci, $SCI_SETSEL, $anchor, $currentPos)
EndFunc


Func FindNext($findWhat,$reverseDirection=False, $showWarnings=True,$flags=0,$showgui=False)
Global $findTarget,$wrapFind,$replacing
If ($findWhat=="") Or ($showgui) Then
If $reverseDirection Then
GUICtrlSetState($rFindDirectionUp,$GUI_CHECKED)
GUICtrlSetState($rFindDirectionDown,$GUI_UNCHECKED)
Else
GUICtrlSetState($rFindDirectionUp,$GUI_UNCHECKED)
GUICtrlSetState($rFindDirectionDown,$GUI_CHECKED)


EndIf
GUISetState(@SW_SHOW,$fFind1)
Return -1
EndIf


$findTarget = $findWhat
$lenFind = StringLen($findTarget)
if ($lenFind == 0) Then
return -1
EndIf


$startPosition = SendMessage($sci,$SCI_GETTARGETEND,0,0)
$endPosition = SendMessage($sci,$SCI_GETLENGTH,0,0)
if ($reverseDirection) Then
$startPosition = SendMessage($sci,$SCI_GETTARGETSTART,0,0)
$endPosition = 0
EndIf
ConsoleWrite("$startPosition="&$startPosition&@CR)
ConsoleWrite("$endPosition="&$endPosition&@CR)


;$flags = ($wholeWord ? SCFIND_WHOLEWORD : 0) |
;            (matchCase ? SCFIND_MATCHCASE : 0) |
;            (regExp ? SCFIND_REGEXP : 0) |
;            (props.GetInt("find.replace.regexp.posix") ? SCFIND_POSIX : 0);


SendMessage($sci,$SCI_SETSEARCHFLAGS, $flags,0);
$posFind = FindInTarget($findTarget, $lenFind, $startPosition, $endPosition)


if ($posFind == -1) And ($wrapFind) Then
if ($reverseDirection) Then
$startPosition = SendMessage($sci,$SCI_GETLENGTH,0,0)
$endPosition = 0;
Else
$startPosition = 0;
$endPosition = SendMessage($sci,$SCI_GETLENGTH,0,0)
EndIf
$posFind = FindInTarget($findTarget, $lenFind, $startPosition, $endPosition);
If ($showWarnings) Then
WarnUser("Reached the end of text. Wrapping around...");
EndIf
EndIf
if ($posFind == -1) Then
$havefound = false;
if ($showWarnings) Then
WarnUser("Can't find the string '"&$findWhat&"'!");
EndIf
Else
$havefound = true;
$start = SendMessage($sci,$SCI_GETTARGETSTART,0,0);
$end = SendMessage($sci,$SCI_GETTARGETEND,0,0);
EnsureRangeVisible($start, $end);
SetSelection($start, $end);
EndIf
return $posFind; 
EndFunc




Func ShowLineNumbers($yes)
$show_line_numbers = $yes
If $yes Then
GUICtrlSetState($mViewLineNumbers,$GUI_UNCHECKED)
SendMessage($sci,$SCI_SETMARGINWIDTHN, 0, 0)
Else
GUICtrlSetState($mViewLineNumbers,$GUI_CHECKED)
$pixelWidth = SendMessageString($sci,$SCI_TEXTWIDTH, $STYLE_LINENUMBER, "99999")
SendMessage($sci,$SCI_SETMARGINWIDTHN, 0, $pixelWidth);
EndIf 
EndFunc


Func ShowWhitespaces($yes)
$show_whitespaces = $yes
If $yes Then
GUICtrlSetState($mViewWhitespaces,$GUI_CHECKED)
SendMessage($sci,$SCI_SETVIEWWS,1,0)
Else
GUICtrlSetState($mViewWhitespaces,$GUI_UNCHECKED)
SendMessage($sci,$SCI_SETVIEWWS,0,0)
EndIf 
EndFunc


Func ShowFolds($yes)
$show_folds = $yes
If $yes Then
GUICtrlSetState($mViewFolds,$GUI_UNCHECKED)
SendMessage($sci,$SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_FOLD_INDEX, 0)


Else
GUICtrlSetState($mViewFolds,$GUI_CHECKED)
SendMessage($sci,$SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_FOLD_INDEX, 20);
EndIf 
EndFunc


Func DetectHighlighter($filename)
if not IsArray($highlighters) Then
return
EndIf
Dim $szDrive, $szDir, $szFName, $szExt,$hl_file
_PathSplit($filename, $szDrive, $szDir, $szFName, $szExt)
$highlighters = _FileListToArray(@ScriptDir,"highlighter.*.txt",1)
for $hi = 1 to $highlighters[0]
$exts = IniRead(@ScriptDir&"\"&$highlighters[$hi],"","ext","")
if StringInStr(StringLower($exts),StringLower($szExt))>0 Then
$hl_file = @ScriptDir&"\"&$highlighters[$hi]
ExitLoop
EndIf
Next
if $hl_file <> "" then 
LoadHiglight($hl_file)
Else
SetStyle($STYLE_DEFAULT,$default_style)
SendMessageString($sci,$SCI_STYLECLEARALL,0,0)
SendMessageString($sci,$SCI_SETLEXER,0,0) 
EndIf
EndFunc


Func SelectHighlighter()
for $i = 0 to UBound($highlighters_menu)-1
if $highlighters_menu[$i] = @GUI_CTRLID Then
ExitLoop
EndIf
Next
LoadHiglight(@ScriptDir&"\"&$highlighters[$i+1])
SendMessageString($sci, $SCI_CANCEL,0,0)
EndFunc


Func ListHighlighters()
$highlighters = _FileListToArray(@ScriptDir,"highlighter.*.txt",1)
if not IsArray($highlighters) Then
return
EndIf
for $hi = 1 to $highlighters[0]
$mi = GUICtrlCreateMenuitem ( IniRead(@ScriptDir&"\"&$highlighters[$hi],"","name",""), $mHighlighter,$hi)
GUICtrlSetOnEvent(-1,"SelectHighlighter")
$highlighters_menu[UBound($highlighters_menu)-1] = $mi
ReDim $highlighters_menu[UBound($highlighters_menu)+1]
Next


EndFunc


Func SetStyle($style,$styletxt)
$astyle = StringSplit($styletxt,",")


if UBound($astyle)<8 Then
;MsgBox(16,"Warning","Incomplete style definition, skipping..."&@CRLF&$styletxt)
Return
EndIf


SendMessage($sci,$SCI_STYLESETFORE,$style,$astyle[1])
SendMessage($sci,$SCI_STYLESETBACK,$style,$astyle[2])
if $astyle[3] >= 1 Then
SendMessage($sci,$SCI_STYLESETSIZE,$style,$astyle[3]) 
EndIf
if $astyle[4] <> '' Then
SendMessageString($sci,$SCI_STYLESETFONT,$style,$astyle[4]) 
EndIf
SendMessage($sci,$SCI_STYLESETBOLD,$style,$astyle[5])
SendMessage($sci,$SCI_STYLESETITALIC,$style,$astyle[6])
SendMessage($sci,$SCI_STYLESETUNDERLINE,$style,$astyle[7])
EndFunc


Func GetSelLength($sci)
$startPosition = SendMessage($sci,$SCI_GETSELECTIONSTART,0,0)
$endPosition = SendMessage($sci,$SCI_GETSELECTIONEND,0,0)
$len = $endPosition-$startPosition 
Return $len
EndFunc


CreateEditor()
FitEditor()
InitEditor()
NewFile()


While 1
If (WinActive($Form1)) Then
If _IsPressed("72",$user32) Then;F3
FindNext($findWhat,False, $showWarnings,$flags,False)
EndIf


If _IsPressed("10",$user32) And _IsPressed("72") Then ;Shift+F3
FindNext($findWhat,True, $showWarnings,$flags,False)
EndIf


If _IsPressed("10",$user32) And _IsPressed("53",$user32) Then;Shift+S
SaveFile("")
EndIf


If _IsPressed("11",$user32) And _IsPressed("53",$user32) Then;Ctrl+S
SaveFile()
EndIf


If _IsPressed("11",$user32) And _IsPressed("4F",$user32) Then;Ctrl+O
OpenFile()
EndIf


If _IsPressed("11",$user32) And _IsPressed("4E",$user32) Then;Ctrl+O
NewFile()
EndIf


If _IsPressed("11",$user32) And _IsPressed("47",$user32) Then;Ctrl+G
GoToLine()
EndIf


If _IsPressed("11",$user32) And _IsPressed("46",$user32) Then;Ctrl+F
$len = GetSelLength($sci)
If $len>0 Then
$text = DllStructCreate("char["&$len+1&"]")
DllCall($user32, "int", "SendMessageA", "hwnd", $sci, "int", $SCI_GETSELTEXT, "int", 0, "ptr", DllStructGetPtr($text))
$findWhat = DllStructGetData($text,1)
$text = 0
EndIf
GUICtrlSetData($Combo1,$findWhat,$findWhat)
FindNext($findWhat,False, $showWarnings,$flags,True)
EndIf
EndIf


Sleep(100)
WEnd

[EDIT] also found this but same problem here:

#include <GuiConstants.au3>
;The SCI_* Values are found at classQextScintillaBase.html in the resource list
Global Const $SCI_START = 2000
Global Const $SCI_ADDTEXT = $SCI_START + 1
Global Const $SCI_APPENDTEXT = $SCI_START + 282
Global Const $SCI_INSERTTEXT = $SCI_START + 3
Global Const $SCI_CLEARALL = $SCI_START + 4
Global Const $SCI_SETSELBACK = $SCI_START + 68
; Generic error handler for DllCall
Func errDllCall($err, $ext, $erl=@ScriptLineNumber)
   Local $ret = 0


   If $err <> 0 Then
      ConsoleWrite("(" & $erl & ") := @error:=" & $err & ", @extended:=" & $ext & @LF)
      $ret = 1
   EndIf
   Return $ret
EndFunc
; API Wraper function
Func CreateWindowEx($dwExStyle, $lpClassName, $lpWindowName="", $dwStyle=-1, $x=0, $y=0, $nWidth=0, $nHeight=0, $hwndParent=0, $hMenu=0, $hInstance=0, $lParm=0 )
   Local $ret
   If $hInstance=0 Then
          ;TODO: Do we need to provide the instance handle?
      $ret = DLLCall( "user32.dll","long","GetWindowLong","hwnd",$hwndParent,"int",-6); $GWL_HINSTANCE=-6
      $hInstance = $ret[0]
   EndIf
   $ret =  DllCall("user32.dll", "hwnd", "CreateWindowEx", "long", $dwExStyle, _
            "str", $lpClassName, "str", $lpWindowName, _
            "long", $dwStyle, "int", $x, "int", $y, "int", $nWidth, "int", $nHeight, _
            "hwnd", $hwndParent, "hwnd", $hMenu, "long", $hInstance, "ptr", $lParm)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc
; API Wraper function
Func LoadLibrary($lpFileName)
   Local $ret
   $ret = DllCall("kernel32.dll", "int", "LoadLibrary", "str", $lpFileName)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc
; API Wraper function
Func SendMessage($hwnd, $msg, $wp, $lp)
   Local $ret
   $ret = DllCall("user32.dll", "long", "SendMessageA", "long", $hwnd, "long", $msg, "long", $wp, "long", $lp)
   Return $ret[0]
EndFunc
; API Wraper function
Func SendMessageString($hwnd, $msg, $wp, $str)
   Local $ret
   ; TODO: VB Any translated to ptr ???
   $ret = DllCall("user32.dll", "long", "SendMessageA", "long", $hwnd, "long", $msg, "long", $wp, "str", $str)
   Return $ret[0]
EndFunc
; API Wraper function
Func SetWindowPos($hwnd, $style, $left, $top, $width, $height, $flags)
   ;TODO: Verify implementation.
   Local $ret
   $ret = DllCall("user32.dll", "long", "SetWindowPos", "long", $hwnd, "long", $style, _
   "long", $left, "long", $top, "long", $width, "long", $height, _
   "long", $flags)
   If errDllCall(@error, @extended) Then Exit
   Return $ret[0]
EndFunc


Func Main()
    Local $GWL_HINSTANCE = -6
    Local $sci
    Local $gui = GUICreate("MyScite", 600, 600, 10, 10)
    Local $hLib = LoadLibrary("SciLexer.DLL")


    Local $hInstance = 0
    $sci = CreateWindowEx($WS_EX_CLIENTEDGE, "Scintilla", _
            "TEST", BitOR($WS_CHILD, $WS_VISIBLE), 100, 100, 200, 200, _
            $gui, 0, $hInstance, 0)


    SetWindowPos($sci, 0, 5, 5, 600 - 10, 600 - 100, 0)


    GUISetState(@SW_SHOW)


    Local $btn1 = GUICtrlCreateButton("Add", 0, 550)
    Local $btn2 = GUICtrlCreateButton("Append", 80, 550)
    GUISetState(@SW_SHOW)
    Sleep(1000)
    SciAddText($sci, "Hello I'm Scintilla..:)" & @CRLF)
    Sleep(1000)
    SciAppendText($sci, "And I'm getting hungry" & @CRLF)
    ;Sleep(1000)
    ;SciClearAll($sci)


    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case 0
                Sleep(100)
            Case $btn1
                SciAddText($sci, "Hello I'm Scintilla..:)" & @CRLF)
            Case $btn2
                SciAppendText($sci, "I'm getting hungry" & @CRLF)
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Main
Func SciAddText($hwnd, $text)
   SendMessageString( $hwnd, $SCI_ADDTEXT, StringLen($text), $text)
EndFunc
Func SciAppendText($hwnd, $text)
   SendMessageString( $hwnd, $SCI_APPENDTEXT, StringLen($text), $text)
EndFunc
Func SciClearAll($hwnd)
   SendMessageString( $hwnd, $SCI_CLEARALL, 0, 0)
EndFunc
;Run application
Main()
Exit
Edited by TheAutomator
Link to comment
Share on other sites

What you probably should be looking at is "scintilla.h.au3" which is referenced in the above code.

If there are any calls to the dll you want to learn about, they'll probably be in that.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

JohnOne,

What you probably should be looking at is "scintilla.h.au3" which is referenced in the above code.

If there are any calls to the dll you want to learn about, they'll probably be in that.

 

"scintilla.h.au3" is just 1739 lines with constands:

Global Const $SCE_OPAL_DEFAULT=32Global Const $SCE_SPICE_DEFAULT=0
Global Const $SCE_SPICE_IDENTIFIER=1
Global Const $SCE_SPICE_KEYWORD=2
Global Const $SCE_SPICE_KEYWORD2=3
Global Const $SCE_SPICE_KEYWORD3=4
Global Const $SCE_SPICE_NUMBER=5
Global Const $SCE_SPICE_DELIMITER=6
Global Const $SCE_SPICE_VALUE=7
Global Const $SCE_SPICE_COMMENTLINE=8
Global Const $SCLEX_ASP=29
Global Const $SCLEX_PHP=30

I found out that the script must be compiled for the scite edit to be visible  >_<

TheAutomator.

Edited by TheAutomator
Link to comment
Share on other sites

JohnOne,

What is exact name of the dll you want to use?

 

SciLexer.dll is the exact name :)

The script only works if it is compiled so it makes it again more difficult to try to understand how to use it  :wacko:

This page sort of explains how to use the dll:

http://www.scintilla.org/Steps.html

but I use AutoIT and i'm a beginner with dll calls..

This is something you can't possibly learn without help from just reading that site if you can't even call a dll.

TheAutomator.

Link to comment
Share on other sites

This is something you can't possibly learn without help from just reading that site if you can't even call a dll.

TheAutomator.

I agree, which is why you should start making calls to standard windows dlls before proceeding.

If you look in WinApi.au3 you will see hundreds of dll calls wrapped for use with AutoIt.

Look at what functions they are calling and find the same on msdn to learn what's going on and why.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Great UDF by kip

'?do=embed' frameborder='0' data-embedContent>>

The previous versions require an include that I couldnt find but on page 4 ProgAndy attached the version that worked for me

page-4'>page-4

A good starting point would be to read over Kips UDF and see how he did it.

The documentation for the SciLexer.dll can be found here as well,

http://www.scintilla.org/ScintillaDoc.html

Link to comment
Share on other sites

MBALZESHARI,
 
Yes, I'm using scite.
The reason I want to make my own version is that I can choose what's in the menu's and to learn
making dll calls for the SciLexer.dll.
I wanted to make my own syntax highlighter for a long time now but every time I get discouraged becouse it's not that simple.
I'm going to look at the other reply's but probably I use the scite exe before learning further in dll calling.
Thanks.  :)
 
JohnOne,
 
Good idea, i'm going to look at WinApi.au3, maybe it's Chinese for me but i'm going to try to understand how it works,
maybe some tutorials online could help me to.
Thanks for the advice.  :)
 
BuckMaster,
 
Thanks for the links, I've saw them before (the udf's) and downloaded them before I started this topic.
The ScintillaDoc explains how it works and most of the time C++ terms are used (the language I want to learn but a lot I still don't understand much about c and c++).
The script I tried to understand the most is "sciteit.au3" but with no success.
Its a bit to advanced to understand these for now I think  :(
 
TheAutomator.
Edited by TheAutomator
Link to comment
Share on other sites

#include <WinAPI.au3>

MsgBox(0, "Native AutoIt", "Yoo Hoo!")

_WinAPI_MsgBox(0, "_WinAPI AutoIt", "Yoo Hoo!")

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
DllCall("User32.dll", "int", "MessageBox", "HWND", 0, "str", "Yoo Hoo!", "str", "DllCall AutoIt", "UINT", 0)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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