Class RichEdit - update on 2015-04-14 (v0.1.05.00)

Post your working scripts, libraries and tools for AHK v1.1 and older
Kliemann
Posts: 6
Joined: 20 Jan 2016, 09:07

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

27 Jan 2016, 08:00

Well, up to now I couldn't figure out how to disable redrawing. Any clue???
Kliemann
Posts: 6
Joined: 20 Jan 2016, 09:07

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

28 Jan 2016, 07:19

The wordwrap switching approach has some drawbacks, but after a while I came up with an 'acceptable' solution thanks to the possibility of obtaining the absolute caret position and to a particularity of the stringreplace function, which I could then use to quickly count the occurrences of carriage-returns in the plain text. However, this solution may not perform well on long texts (not tested yet). My code is below:

Code: Select all

cp := 0
SendMessage, 0xB0, &cp, 0, , % "ahk_id " . RE2.HWND
cp := NumGet(cp, 0, "UInt") + 1 ; Absolute caret position
s := RE2.GetText()
if (cp>1)
 stringleft, s, s, % (cp-1)
else
 s := ""
stringreplace, s, s, `r, `r, UseErrorLevel
paragraph := ErrorLevel+1

Now, for the next step, I am interested in a way to set the absolute caret position...
a_ber
Posts: 14
Joined: 15 Mar 2016, 14:52

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

15 Mar 2016, 15:01

hy just me,

first, you app is really great! i use it to show dedicated information on a very simple rtf gui. my problem is to follow links (email adr. or www) shown in the gui. is there a possibility to make it happen? i use win 10 x64 and the latest ahk compiler.


best regards
andreas
Attachments
ahk.jpg
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

16 Mar 2016, 03:08

Hi Andreas,

do you speak German? If so, you'll find some hints in this german thread: Fragen zum RichEdit Control.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

17 Mar 2016, 11:40

First off, great Class, thanks for sharing just me.
I just recently started messing with it and was wondering if it is possible to change text format without having to select it.
i.e. use RE.SetFont({BkColor: VarHasColor}) on a text by defining its start/end without changing current selection.
a_ber
Posts: 14
Joined: 15 Mar 2016, 14:52

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

17 Mar 2016, 12:20

hy,

yes i'm fluent in german ;-) and thanks again for your tip - after a nightshift yesterday it works ...

br from vienna
andreas
a_ber
Posts: 14
Joined: 15 Mar 2016, 14:52

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

17 Mar 2016, 15:05

zu früh gefreut, bei win10 tritt folgender fehler nach dem klicken auf eine mailadress auf (siehe screenshot). der aufruf ist simple:

cpMax := NumGet(A_EventInfo + 0, (A_PtrSize * 5) + 8, "Int")
URLtoOpen := GetTextRange(RE2.HWND, cpMin, cpMax)
Run, %URLtoOpen%

bei win7 ist alles gut (jeweils 64bit)
Attachments
2016-03-17_210237.jpg
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

18 Mar 2016, 01:52

@AlphaBravo: You can change the text attributes either for the current selection or for text subsequently entered after the current caret position.

@a-ber: I'm running Win 10 and will check it.
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

18 Mar 2016, 10:08

@a-ber:

I cannot reproduce the problem here (Win 10 x64). Would you please provide the complete code used in the message handler?
BTW: GetTextRange() is a built-in method now and I used it instead of your function call.
a_ber
Posts: 14
Joined: 15 Mar 2016, 14:52

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

18 Mar 2016, 10:53

here we are ...

Code: Select all

	Options := "w500 h480 gRE2MessageHandler"
		If !IsObject(RE2 := New RichEdit(1, Options)) 		; define window
		{
		MsgBox, 16, Error, %ErrorLevel%
		ExitApp
		}
	RE2.SetEventMask(["LINK"])	
	RE2.SetOptions(["READONLY"], "SET")
;	RE2.AutoURL(1)
	RE2.WordWrap(1)

Code: Select all

RE2MessageHandler:
If (A_GuiEvent = "N") {
   Msg := NumGet(A_EventInfo + 0, A_PtrSize * 2, "Int")
   If (Msg = 0x0702) { 										; EN_SELCHANGE
    Return
   }
   If (Msg = 0x070B) { 										; EN_LINK
    Message := NumGet(A_EventInfo + 0, A_PtrSize * 3, "Int")
    If (Message = 0x0202) { 								; WM_LBUTTONUP
        wParam  := NumGet(A_EventInfo + 0, (A_PtrSize * 3) + 4, "UPtr")
        lParam  := NumGet(A_EventInfo + 0, (A_PtrSize * 4) + 4, "UPtr")
        cpMin   := NumGet(A_EventInfo + 0, (A_PtrSize * 5) + 4, "Int")
        cpMax   := NumGet(A_EventInfo + 0, (A_PtrSize * 5) + 8, "Int")
        URLtoOpen := GetTextRange(RE2.HWND, cpMin, cpMax)
		Run, %URLtoOpen%
	}
    Return
   }
} Else {
   If (A_EventInfo = 0x0100) 								; EN_SETFOCUS
		HasFocus := True
   Else If (A_EventInfo = 0x0200) 							; EN_KILLFOCUS
		HasFocus := False
}
Return

GetTextRange(HWND, cpMin, cpMax) {
   Static EM_GETTEXTRANGE := 0x044B
   Len := cpMax - cpMin 									; Länge berechnen
   VarSetCapacity(Text, Len << !!A_IsUnicode, 0) 			; Bereich für den Text
   VarSetCapacity(TEXTRANGE, 16, 0) 						; TEXTRANGE Struktur
   NumPut(cpMin, TEXTRANGE, 0, "UInt")
   NumPut(cpMax, TEXTRANGE, 4, "UInt")
   NumPut(&Text, TEXTRANGE, 8, "UPtr")
   SendMessage, %EM_GETTEXTRANGE%, 0, % &TEXTRANGE, , ahk_id %HWND%
   VarSetCapacity(Text, -1) 								; Länge des Zeichenspeichers korrigieren 
   Return Text
}
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

19 Mar 2016, 02:43

Hi a_ber,

I still cannot reproduce any problems here. Can you provide an example of your predefined RTF files?
a_ber
Posts: 14
Joined: 15 Mar 2016, 14:52

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

19 Mar 2016, 08:39

hy, i changed the beginning of my script and now all the links (www and mail) work both in win10 & win7. but i have no clue why ;-)

Code: Select all

	Clipboard :=
	;Send, ^{Left}+^{Right}^c								; get word under mouse/cursor
	Send, {LButton 2}^c	
	ClipWait, 3
btw, i also commented out "SendMode, Input", which caused problems in getting text under cursor.

you mentioned that "GetTextRange()" is now system built in, how look like the code instead?

thx & best regards
andreas
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

19 Mar 2016, 10:42

Code: Select all

RE2MessageHandler:
If (A_GuiEvent = "N") {
   ...
   If (Msg = 0x070B) { 										; EN_LINK
      Message := NumGet(A_EventInfo + 0, A_PtrSize * 3, "Int")
      If (Message = 0x0202) { 								; WM_LBUTTONUP
         wParam  := NumGet(A_EventInfo + 0, (A_PtrSize * 3) + 4, "UPtr")
         lParam  := NumGet(A_EventInfo + 0, (A_PtrSize * 4) + 4, "UPtr")
         cpMin   := NumGet(A_EventInfo + 0, (A_PtrSize * 5) + 4, "Int")
         cpMax   := NumGet(A_EventInfo + 0, (A_PtrSize * 5) + 8, "Int")
         URLtoOpen := RE2.GetTextRange(cpMin, cpMax) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
         Run, %URLtoOpen%
      }
      Return
   }
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

04 Nov 2016, 05:35

Hi BGM :salute:
Could you please help me with this.
RichEdit.ahk highlight help bold and red color https://autohotkey.com/boards/viewtopic.php?f=5&t=24339
Thank You
BGM wrote:Okay!

Here is a working SIMPLE example of using the RichText Class for folks who just want the basics.

It demonstrates:
  • How to add the control
  • How to use ToggleFontStyle (which I did find in the class file)
  • How to colourize using richtext tags
  • How to insert and clear text content
  • How to fetch the content using the v-variable in the control's options
screenshot_AutoHotkey (AutoHotkey Unicode 32-bit)_005.png

Code: Select all

#NoEnv
SetBatchLines, -1
#include Class_RichEdit.ahk

appname := "SimpleRichEdit"
gosub, mainui
gosub, loadhotkeys
return
;------------------------------
mainui:
   Gui, +Hwnd%appname%
    MyRichEdit := new richedit(%appname%,"w250 vmyedit", true)
    MyRichEdit.AlignText("RIGHT")
    Gui, Show, h120 w270 center,%appname%
Return
;------------------------------
Message:
   guicontrolget, myedit
    ToolTip, My contents are %myedit%
    settimer, removemessage, 1000
return
RemoveMessage:
	settimer, removemessage, off
	tooltip
return
;------------------------------
LoadHotkeys:
	hotkey, IfWinActive, % "ahk_id " %appname% ; <------
	hotkey, ^b, MakeBold
	hotkey, ^+b, MakeBold_alt
	hotkey, ^g, MakeColoured
	hotkey, ^t, Message
	hotkey, ^q, Clear
return
;------------------------------
;For syntax using the richtext tags:
;http://www.pindari.com/rtf1.html

;Demonstrate using the class' built-in ToggleFontStyle for the current selection
MakeBold:
	MyRichEdit.ToggleFontStyle("B")
return
;Demonstrate setting of tag-styled text
MakeBold_alt:
	MyRichEdit.SetText("{\rtf My Name is \b1 " . appname . "\b0}", ["SELECTION"])
return

MakeColoured:
	colortable := "{\colortbl `;\red0\green176\blue80;\red0\green77\blue187`;\red255\green0\blue0`;}"
	greentext := "\cf1 green text,\cf0"
	bluetext := "\cf2  blue text,\cf0"
	redtext := "\cf3  red text\cf0"	
	MyRichEdit.SetText("{\rtf " . colortable . "Colouized text: " . greentext . bluetext . redtext . ".}", ["SELECTION"])
return
Clear:
	MyRichEdit.SetText("")
return
;------------------------------
GuiClose:
ExitApp
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

25 Jan 2018, 15:42

Hi just me, hello all, ;)

I have been implementing this great class into a project for some time now.
I did a few improvements but mostly minors until now because I am not very at ease with msdn documentation.

However there are some more complicated features that I think would be really great to implement.

If someone is up for the challenges and could at least give a first try/look that would be wonderful ! 8-)

Here what I think could be added/improved. What do you think about it?
@just me: do you think some of these are possible?

Support for OLE object = embedded objects of Powerpoint, Excel spreadsheet and other files!
Considering what I saw here :
https://www.codeproject.com/Articles/95 ... s-and-Othe
that might be possible !
By the way, it seems autoit has implemented it no?
https://github.com/forcedotcom/dataload ... chEdit.au3

Support for images in Win 7:
I know this has been asked and answered that image support wworks on win>8 but for what I've read there might be the solution to load images as bitmap using Gdip so that win 7 would display images.
https://www.autoitscript.com/forum/topi ... e-problem/
However I have not been able to even see a icon of the image using the class.
If I use RE2.SetEventMask(["DROPFILES"]) and/or set RichEditGuiDropFiles label, that doesn't seem to produce something.

Friendly Hyperlink
I have been like others be able to implement AutoURL detection but then you have to put the link as such.
It would be great to have a text independant from the link.
The best would be to be able to right clic it and even be able to enter a new label for the link after it has been added.
But first things first.
Here are some documentation
https://blogs.msdn.microsoft.com/murray ... yperlinks/
https://stackoverflow.com/questions/425 ... -trichedit

I have given a try:
Spoiler
Well I will probably try a bit harder soon but I kindda su** at it so any help would be great :D
Thanks !
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

25 Jan 2018, 15:52

By the way here is a small contribution of my own ;)

Insert clickable links of files by drag-and-drop

Code: Select all

RichEditGuiDropFiles:
;Assuming you have the gui hwnd in RN_CurrentHwnd
	FileDropped:=1
	WinActivate, % "ahk_id " RN_CurrentHwnd
	GuiControl, Focus, % RE2.HWND
	RE2.SetSel(RE2.Sel.S,RE2.Sel.E)
	Loop, parse, A_GuiEvent, `n
		{
		VariableToSend:="file://" . StrReplace(A_LoopField," ", "%20") . "`n"
		RE2.LoadVariable(VariableToSend,"Insert")
		}
	FileDropped:=""
return
and add this in UpdateRNGui

Code: Select all

if !(FileDropped)
	RE2.Sel := RE2.GetSel()
I have come to find this solution to get the Sel so that you can insert filelinks where you were and not just append them.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

25 Jan 2018, 17:28

Hi DigiDon,

I lost interest in maintaining this class furthermore. Do you want to continue? If so, open a new thread, please. I'll add a link to the new thread and ask the mods to close this one.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

26 Jan 2018, 07:34

Hi everyone,

We've PMed with just me and I asked for some time before deciding to pick up the topic.
I would need some help because this goes beyound my capabilities right now. So the question is:
Who could be interested in trying to improve this class with me on these topics?
So please don't hesitate to contact me and/or post here if you think you could help with these subjects
Cheers ! :)

Support for OLE object = embedded objects of Powerpoint, Excel spreadsheet and other files!
https://www.codeproject.com/Articles/95 ... s-and-Othe

Support for images in Win 7:
https://www.autoitscript.com/forum/topi ... e-problem/

Friendly Hyperlink
https://blogs.msdn.microsoft.com/murray ... yperlinks/
https://stackoverflow.com/questions/425 ... -trichedit

AutoIt class (for reference)
https://github.com/forcedotcom/dataload ... chEdit.au3
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

27 Jan 2018, 10:12

EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble, peter_ahk and 125 guests