kashamalasha

Syntax Highlighting in RichEdit element

5 posts in this topic

Hi everybody.

Could you tell me is there any UDF that can help to highlight syntax in the _GUICtrlRichEdit element on the fly?

Is it possible to implement this feature in script in simple way using some UDF or something, instead of writing thousand of strings manually?

Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

It was discused here on the forum few times for Au3 Syntax.
For what Language you need it ?

EDIT:

 

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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 API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

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 * Best coding practices * 

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) * 

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 *

"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: 2017-06-04

Share this post


Link to post
Share on other sites

I've tried your UDF, and it is not exact what I want.

I want to implemnt syntax highlighting for the text on the fly. That means it should work like syntax highlighting in Notepad++ or like in Sublime Text editors. The user shouldn't push any button to highlight text in the editor.

Thanks.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

UPD: I found some script that works very similar with my requirements. But it can't react when I edit some text that has been already written. Could you help me fix it?

Thanks.

#include <guiconstantsex.au3>
#include <guirichedit.au3>
#include <windowsconstants.au3>
#include <misc.au3>
opt('guioneventmode', 1)
global $g_hrichedit

doit()

func doit()
   local $hgui, $imsg, $idbtnnext, $istep = 0
      $hgui = guicreate("", 320, 350, -1, -1)
      $g_hrichedit = _guictrlrichedit_create($hgui, "", 10, 10, 300, 220, _
      bitor($es_multiline, $ws_vscroll, $ws_hscroll, $es_autovscroll))
      guisetonevent($gui_event_close, '__exit')
      guisetstate(@sw_show)
      global $dll_32 = dllopen('user32.dll')
      sleep(2000)

    while 1
      sleep(100)
            $last = 1000000
            if (_ispressed(11, $dll_32) = false) and (_ispressed("08", $dll_32) _
            or _ispressed(41, $dll_32) or _ispressed(42, $dll_32) or _ispressed(43, $dll_32) _
            or _ispressed(44, $dll_32) or _ispressed(45, $dll_32) or _ispressed(46, $dll_32) _
            or _ispressed(47, $dll_32) or _ispressed(48, $dll_32) or _ispressed(49, $dll_32) _
            or _ispressed('4a', $dll_32) or _ispressed('4b', $dll_32) or _ispressed('4c', $dll_32) _
            or _ispressed('4d', $dll_32) or _ispressed('4e', $dll_32) or _ispressed('4f', $dll_32) _
            or _ispressed(50, $dll_32) or _ispressed(51, $dll_32) or _ispressed(52, $dll_32) _
            or _ispressed(53, $dll_32) or _ispressed(54, $dll_32) or _ispressed(55, $dll_32) _
            or _ispressed(56, $dll_32) or _ispressed(57, $dll_32) or _ispressed(58, $dll_32) _
            or _ispressed(59, $dll_32) or _ispressed('5a', $dll_32)) then


                  for $i = 1 to 2  
                        guisetcursor(-1, '', $hgui)
                        _guictrlrichedit_pauseredraw($g_hrichedit)
                        $pos1 = _guictrlrichedit_getcharposofpreviousword($g_hrichedit, $last)
                              if $pos1 < 0 then
                                    $i = 2
                              else
                                 _guictrlrichedit_setsel($g_hrichedit, $pos1, $last)
                                 $last = $pos1
                                 $text = _guictrlrichedit_getseltext($g_hrichedit)
                                       if stringregexp($text, '(?:^func[ ]{0,100}$|^endfunc[ ]{0,100}$|^if[ ]{0,100}$|^endif[ ]{0,100}$)') then
                                                _guictrlrichedit_setcharcolor($g_hrichedit, 0x000099)
                                                _guictrlrichedit_setsel($g_hrichedit, -1, -1)
                                       elseif stringregexp($text, '(?:^include[ ]{0,100}$)') then
                                                _guictrlrichedit_setcharcolor($g_hrichedit, 0x009900)
                                                _guictrlrichedit_setsel($g_hrichedit, -1, -1)
                                       else
                                                _guictrlrichedit_setcharcolor($g_hrichedit, 0x000000)
                                                _guictrlrichedit_setsel($g_hrichedit, -1, -1)
                                       endif
                                 _GUICtrlRichEdit_GetCharPosFromXY($g_hrichedit, $hCharPos[0], $hCharPos[1])
                              endif
                  next
            _guictrlrichedit_resumeredraw($g_hrichedit)
            endif
    wend
endfunc


func __exit()
            dllclose('user32.dll')
            exit
endfunc

 

Edited by kashamalasha

Share this post


Link to post
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

  • Similar Content

    • loganizzi
      By loganizzi
      If you look at the help file for the above command, you'll see that it states that it only works for certain zoom values (100 and 200 to 6400).   I assume that this is due to an issue in an MSDN library that the command relies on.
      After doing some investigating, I noticed that the GUIRichEdit.au3 library file contains the following code:
      ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom Which ensures that values are only within the bounds specified in the help file.    I found that if I comment out the portion of the code that limits the values, the function works fine for most (if not all) values.   I changed the code in the library file to this by simply commenting out the restricting lines of code:
      ; #FUNCTION# ==================================================================================================================== ; Authors........: Chris Haslam (c.haslam) ; Modified ......: ; =============================================================================================================================== Func _GUICtrlRichEdit_SetZoom($hWnd, $iPercent) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) If Not __GCR_IsNumeric($iPercent, ">0") Then Return SetError(1021, 0, False) Local $iNumerator, $iDenominator Select ; Case Not ($iPercent = 100 Or ($iPercent >= 200 And $iPercent < 6400)) ; Return SetError(1022, 0, False) Case $iPercent >= 100 $iNumerator = 10000 $iDenominator = 10000 / ($iPercent / 100) Case Else $iNumerator = 10000 * ($iPercent / 100) $iDenominator = 10000 EndSelect Return _SendMessage($hWnd, $EM_SETZOOM, $iNumerator, $iDenominator) <> 0 EndFunc ;==>_GUICtrlRichEdit_SetZoom  
      I assume whatever windows bug existed at the time this was created, no longer exists so there is no need to restrict the values.   
      Just wanted to point this out if anyone else is using this part of the library and required this functionality like I did.
       
    • AndreyS
      By AndreyS
      Tell me, please, how to set / change the cursor over RichEdit (created with _GUICtrlRichEdit_Create)?
    • StMaSi
      By StMaSi
      Two questions...
      When presenting a form containing a richedit control, is there any way to make the displayed text, within said richedit control, non-selectable?
      In addition, is there any way to hide the vertical line cursor, within said richedit control?
      Thanx.
    • TheSaint
      By TheSaint
      I've finally come up with some simple solutions for dragging & dropping a URL onto a control.
      There have been many requests here for this over the years.
      I do have an issue though, with my second code example solution as is mentioned here.
      The issue relates to working in Win 7 (and no doubt newer Windows).
      As I state there, failure is no doubt due to 'MSCOMCT2.OCX' missing from the System32 folder, at the very least.
      Not sure if it would be wise to just dump 'MSCOMCT2.OCX' from WinXP into the Win 7 System32 folder. I expect not.
      I imagine there is a better solution available in Win 7. Maybe a different OCX file, and perhaps a different Class of object etc.
      Any help would be greatly appreciated.
      Code is here (second example).
      EDIT
      Okay, I have rediscovered that 'MSCOMCT2.OCX' is a VB6 ActiveX control. So while I could dig up a copy and register it, that would probably not be helpful to everyone.
      And registering it didn't help. Possibly other dependencies are also needed?
      When running the script, it is clear going by the error reported, that Object is not being created.
    • AndreyS
      By AndreyS
      Please tell me, who knows how to apply and cancel styles in RTF?
      The following code does not work:
      #include <GuiRichEdit.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("RichEdit Style", 500, 500, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "Test", 20,40,460,400) GUISetState(@SW_SHOW, $hGUI) Sleep(3000) GUICtrlSetStyle($hRichEdit, $ES_RIGHT) Sleep(3000) GUICtrlSetStyle($hRichEdit, -1) Sleep(3000) Thanks!