Page 1 of 1

[AHK v2] RichEdit Class

Posted: 14 Nov 2018, 00:16
by oif2003
 tl;dr: 
    myRichEditCtrlObj := new RichEdit(parentGuiObj, OptionalOptionsString, OptionalDefaultTextorRTF)
    After that use it like a regular Edit control object


Hi,

Here's the RichEdit class I have been using. It was originally made by just me (https://github.com/AHK-just-me/Class_RichEdit) and has been modified and enhanced by many others since then. I updated it for AutoHotkey v2 and added support for a few standard Edit control properties and methods. Specifically, it now supports: OnEvent(), Focus(), and Move(). Supported events are "Change", "Focus", and "LoseFocus". As for properties, it supports Hwnd, Enabled, Focused, Name, Pos, Type, Visible, Value, and Text (equivalent to Value). Options supported at time of control creation are: +/-wrap, readonly, uppercase, lowercase, standard size/position settings (x, y, w, h), styles & exstyles (the 0x and E0x options), and a user-defined default text. The goal is to make the syntax similar to that of a regular Edit control.

Code: Select all

#singleinstance force
#include Class_RichEdit.ahk

;	It can handle RTF format
re1DefautText := 	  "{\rtf1\ansi\ansicpg1252\deff0\nouicompat{\fonttbl{\f0\fnil\fcharset0 Consolas;}}"
				. "{\colortbl `;\red255\green255\blue0;\red0\green0\blue255;}"
				. "{\*\generator Riched20 10.0.17134}\viewkind4\uc1 "
				. "\pard\cf1\highlight2\ul\b\i\lang1033 This is a RichEdit Box\par"
				. "}"
					
gui := guicreate()
gui.setfont("s10", "Consolas")
eb := gui.add("edit", "r10 w400", "This is an Edit Box")

; 	This is how you create them
; 	be sure the first argument is the gui object.  Syntax is similar to what you would use for Edit box
; 	implemented options:  +/-wrap, readonly, uppercase, lowercase,styles & exstyles
; 	(see Class_RichEdit's constructor __New())
re1 := new richedit(gui, "r10 w400", re1DefautText)
re2 := new richedit(gui, "r5 w400 readonly", "This is a read-only RichEdit Box`n")

;	These are the only supported events for .onEvent()
;	for other RichEdit specific events, see Class_RichEdit.ahk's SetEventMask()
re1.OnEvent("change", ()=>output("RichEdit content has changed.")) 
re1.OnEvent("focus", ()=>output("RichEdit has gained focus.")) 
re1.OnEvent("losefocus", ()=>output("RichEdit has lost focus.")) 

gui.show()

;	Supported properties:
;		Gui - parent gui object (the one you passed when creating this RichEdit control
;		Hwnd - the control's hwnd
;		Also supports: Enabled, Focused, Name, Pos, Type, Visible, Value, and Text (equivalent to Value)
;
;		For RTF specific features, see Class_RichEdit.ahk for usage of
;			SetFont, GetRTF, SetSel, .... etc

output("Its size and position: w" re1.pos.w " h" re1.pos.h " x" re1.pos.x " y" re1.pos.y)


output(msg) {
	global gui, re2
	re2.value .= msg "`n" ;you can also use re2.text here
	PostMessage(0x115, 7, ,re2.hwnd , "ahk_id " gui.hwnd) ;scroll to end of control
}
To see how it is used, see RichEdit_demo.ahk. You will also need to download Class_RichEdit.ahk.
https://github.com/oif2003/RichEditBox/ ... o.ahk?ts=4
https://github.com/oif2003/RichEditBox/ ... t.ahk?ts=4
credit: Just Me, majkinetor, corrupt, jballi, DigiDon, and burque505

Image

Edit: Fixed typos, formatting

Re: [AHK v2] RichEdit Class

Posted: 18 Mar 2023, 11:07
by fenchai
do you plan to updating it? it doenst seem to work on latest v2 atm, I will try to fix if I can.

Re: [AHK v2] RichEdit Class

Posted: 03 Apr 2023, 13:07
by JoeSchmoe
Hi Fenchai, were you able to make any progress updating this?

Re: [AHK v2] RichEdit Class

Posted: 05 Apr 2023, 13:29
by JoeSchmoe
Would anyone be interested in taking this over? @Just Me? @TheArkive? @FanaticGuru, @teadrinker, or anyone else? @oif2003 has only made 2 posts since Dec 2018, a month after he posted this. One was in 2019 and another in 2020. His "last active" field is blank, and this is mostly Just Me's work anyway.

With AHK v2 being official, it'd be great to have a ported version of Just Me's original class.

Re: [AHK v2] RichEdit Class

Posted: 05 Apr 2023, 13:48
by TheArkive
I've thought of doing this, but lately I've been focusing on the Scintilla control (haven't posted latest changes yet). Having said that I've thought about going for this one, but I'm not making it a priority at the moment though.

Re: [AHK v2] RichEdit Class

Posted: 06 Apr 2023, 21:35
by JoeSchmoe
Awesome. While I'd love to have RichEdit, Scintilla is super important, too, and we only have so much time. I'm super grateful for all of the important libraries you converted back when activity on this subforum was far lighter!