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

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Class RichEdit - update on 2015-04-14 (v0.1.05.00)

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

by truekefir » 18 Sep 2018, 14:19

probably worthy addition to library? Hope I did it right
both together allowing to select line containing caret for future use, copy, clear, duplicate, move between controls, etc.

Code: Select all

   
GetCaretLineIndex() { ; Get index of the line containing the caret
	; EM_LINEINDEX = 0xBB
	SendMessage, 0xBB, -1, 0, , % "ahk_id " . This.HWND
	Return ErrorLevel
}
   
GetCaretLineLength() { ; Get length of the line containing the caret
	; EM_LINEINDEX = 0xBB, EM_LINELENGTH = 0xC1
	SendMessage, 0xBB, -1, 0, , % "ahk_id " . This.HWND
	SendMessage, 0xC1, %ErrorLevel%, 0, , % "ahk_id " . This.HWND
	Return ErrorLevel
}

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

by truekefir » 24 Aug 2018, 03:25

Hi!

Is there any better way to insert formatted text into table other than adding it manually like I did in this script?

Code: Select all

#NoEnv
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Menu Tray, Icon, shell32.dll, 190
#include Class_RichEdit.ahk


appname := "richtextthing"
Gui +Resize +LastFound +hwnd%appname%


Gui Add, Button, x1 y1 w80 h23 gDrawTable, DrawTable
Gui Add, Button, x1 y24 w80 h23 gSaveFile, Save
MyRichEdit := new richedit(%appname%,"x81 y1 w736 h575")
MyRichEdit.SetBkgndColor("0x242424")
MyRichEdit.SetDefaultFont({Name: "Courier New", Color: "0xffffff", Size: "8", Style: "B"})
MyRichEdit.SetParaSpacing({Before: "1", After: "1"})
MyRichEdit.ShowScrollBar(0, False)

Gui Show, x1 y1 w800 h600, % appname
Return

DrawTable:
    P_Cols:=2
    P_Rows:=1
	rtfTable := "{\rtf1 {\colortbl `;\red36\green36\blue36;\red51\green246\blue255;\red212\green51\blue255;\red0\green88\blue166;\red148\green0\blue2;\red149\green149\blue149;\red36\green36\blue36;\red255\green255\blue255;}"
	loop % P_Rows
		{
		rtfTable .= "\trowd\trgaph30"
		loop % P_Cols
            {
            rtfTable .= "\clbrdrt\brdrw1\brdrcf1\clbrdrb\brdrw1\brdrcf1\clbrdrl\brdrw1\brdrcf1\clbrdrr\brdrw1\brdrcf1"
            WidthTwips:=Round(4/2.54*1440)+Round(14/2.54*1440)*(A_Index-1)
            rtfTable .= "\cellx" WidthTwips
            }
		loop % P_Cols
			{
            rtfTable .= "\pard\intbl "
            if (A_Index = 1)
                {
                random, lines, 2,3
                fontsize:=round(48/lines)
                rtfTable .= "\qr\fs" . fontsize
                loop % lines
                    {
                    random, underline, 0,1
                    if Underline
                        rtfTable .="\ul"
                    rtfTable .= "\cf" . A_index+1
                    rtfTable .= "Cell 1 Line " A_index
                    if Underline
                        rtfTable .= "\ulnone"
                    rtfTable .= "\par "
                    }
                rtfTable:=SubStr(rtfTable, 1, -5)
                }
            else 
                {
                rtfTable .= "\fs48\cf" . 5
                text:=" Cell " . A_Index . " Cell " . A_Index . " Word " . A_Index . " 1"
                Loop, Parse, text, %A_Space%
                    {
                    if (A_Loopfield = "Cell")
                        {
                        rtfTable .= "\highlight4\fs36 "
                        rtfTable .= A_Loopfield
                        rtfTable .= "\highlight0\fs48 "
                        rtfTable .= " "
                        }
                     else if (A_Loopfield = "2")
                        {
                        rtfTable .= "\highlight6\cf8 "
                        rtfTable .= " " . A_Loopfield . " "
                        rtfTable .= "\highlight0\cf5 "
                        rtfTable .= " "
                        }
                     Else
                        {
                        rtfTable .="\ul "
                        rtfTable .= A_Loopfield
                        rtfTable .= "\ulnone"
                        rtfTable .= "  "
                        }
                    }
                rtfTable := SubStr(rtfTable, 1, -1)
                }
			rtfTable .= "\cell"
			}
		rtfTable .= "\row"
		}
	rtfTable .= "}"
	MyRichEdit.SetText(rtfTable,["SELECTION"])
      MyRichEdit.SetFont({Color: "0x959595", Size: "4", Style: "B"})
   MyRichEdit.SetText("`n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------`n", ["SELECTION"])
return

SaveFile:
    MyRichEdit.SaveFile("tabletest " . A_Now . ".rtf" )
return

GuiEscape:
GuiClose:
    ExitApp
    

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

by burque505 » 13 Feb 2018, 08:25

@DigiDon, @just me, thank for this class and your continued work on it.
Regards,
burque505

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

by DigiDon » 13 Feb 2018, 05:33

moefr01 wrote: Found out that the frame (visible in rtf) of an inserted table is invisible in a converted pdf-file... in contrary to my clipboard-pasting. Looks :ugeek: fine!
Right, I figured this out as well. I've finally managed to add proper borders.
Was not simple because the code from a Word table is quite awfully complicated and RTF syntax for table is... erf!

Anyway here is an improved version that will display table borders well in other programs (at least it should. Works in Word):

Code: Select all

RN_InsertRTFTable(REObj,P_Cols,P_Rows,P_WidthPx) {
global
local rtfTable
; WidthTwips:=Round(P_WidthCM/2.54*1440)
WidthTwips:=Round(P_WidthPx/A_ScreenDPI*1440)
	rtfTable := "{\rtf1\par"
	loop % P_Rows
		{
		rtfTable .= "\trowd\trgaph144"
		loop % P_Cols {
			rtfTable .= "\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 "
			rtfTable .= "\cellx" WidthTwips * A_Index
			}
		rtfTable .= "\pard\intbl "
		loop % P_Cols
			{
			rtfTable .= "\cell"
			}
		rtfTable .= "\row"
		}
	rtfTable .= "\par}"
	; msgbox % rtfTable
	REObj.SetText(rtfTable,["SELECTION"])
}
Notice that I changed from WidthCm (centimeters) to Pixels.

Right now I'm calling it this way so the total width of the table is (such as in Word) always approximately equals to a page width.

Code: Select all

RN_InsertRTFTable(RE2,GridGUICols,GridGUIRows,786/GridGUICols)

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

by moefr01 » 13 Feb 2018, 04:32

DigiDon wrote:Haa, interesting ! ;)

But now you can use my function above to have the number of columns and row you want directly.

You can put two inputbox to ask for value for example or directly use the interface I plan to introduce:
[GUI] Grid selection GUI
thanks DigiDon... your hint works fine. ;)
Found out that the frame (visible in rtf) of an inserted table is invisible in a converted pdf-file... in contrary to my clipboard-pasting. Looks :ugeek: fine!

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

by DigiDon » 12 Feb 2018, 18:00

Hi,

There are still room for improvement to understand and implement clearly the OLE features of Rich Edit into the class and the sample,.
Therefore there are some delays before a proper release.

Nevertheless, for those who would like to start right away I think it is good to release the major part of what was achieved recently.

It is now possible to embed any document into the Rich Edit control

Thanks to the OLE callback interface implementation done by just me and myself.

Many thanks to just me for all the help, work and knowledge you have brought/are still bringing.

Code: Select all

;=========================================
; Name:     	  RichEdit OleCallback
; Namespace:      RichEdit
; Authors:        just me & DigiDon
; Description:    IRichEditOleCallback interface AHK implementation for the RichEdit control
;=========================================
;
;=========================================
;RE_SetOleCallback
;Need to call this function just after creation of the RichEdit control
;HRE - Handle of the RichEdit Control
;ex: RE_SetOleCallback(RE2.HWND)
;Specify your contextmenu in IREOleCB_GetContextMenu() if you have one because it won't be called otherwise
;and disable existing dropfiles special GUI label for the RichEdit Control
;Then you can start dragging and dropping any document into the RichEdit field.
;=========================================
RE_SetOleCallback(HRE) {
   ; EM_SETOLECALLBACK = 0x0446
   SendMessage, 0x0446 , 0, % IREOleCB_Create() , , ahk_id %HRE%
   If (ErrorLevel = "FAIL") || (ErrorLevel = 0) {
      MsgBox, 16, %A_ThisFunc%, ERROR: %ErrorLevel%!
      Return False
   }
   Return True
}
; ================================================================================================================================
; IRichEditOleCallback -> msdn.microsoft.com/en-us/library/windows/desktop/bb774308(v=vs.85).aspx
; ================================================================================================================================
IREOleCB_Create() {
   Static VTBL := [RegisterCallback("IREOleCB_QueryInterface")
                 , RegisterCallback("IREOleCB_AddRef")
                 , RegisterCallback("IREOleCB_Release")
                 , RegisterCallback("IREOleCB_GetNewStorage")
                 , RegisterCallback("IREOleCB_GetInPlaceContext")
                 , RegisterCallback("IREOleCB_ShowContainerUI")
                 , RegisterCallback("IREOleCB_QueryInsertObject")
                 , RegisterCallback("IREOleCB_DeleteObject")
                 , RegisterCallback("IREOleCB_QueryAcceptData")
                 , RegisterCallback("IREOleCB_ContextSensitiveHelp")
                 , RegisterCallback("IREOleCB_GetClipboardData")
                 , RegisterCallback("IREOleCB_GetDragDropEffect")
                 , RegisterCallback("IREOleCB_GetContextMenu")]
   Static HeapSize := A_PtrSize * 20 ; VTBL pointer + 13 method pointers + 4 unused pointers + reference count + HEAP handle
   Static HeapOffset := A_PtrSize * 19 ; offset to store the heap handle within the heap
   Heap := DllCall("HeapCreate", "UInt", 0x05, "Ptr", 0, "Ptr", 0, "UPtr")
   IREOleCB := DllCall("HeapAlloc", "Ptr", Heap, "UInt", 0x08, "Ptr", HeapSize, "UPtr")
   Addr := IREOleCB
   Addr := NumPut(Addr + A_PtrSize, Addr + 0, "UPtr")
   For Each, CB In VTBL
      Addr := NumPut(CB, Addr + 0, "UPtr")
   NumPut(Heap, IREOleCB + HeapOffset, "UPtr")
   Return IREOleCB
}
; --------------------------------------------------------------------------------------------------------------------------------
; IUnknown::QueryInterface
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_QueryInterface(IREOleCB, REFIID, ByRef IFPtr) {
   OutputDebug, %A_ThisFunc%
   Return 0 ; S_OK
}
; --------------------------------------------------------------------------------------------------------------------------------
; IUnknown::AddRef
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_AddRef(IREOleCB) {
   Static RefOffset := A_PtrSize * 18
   OutputDebug, %A_ThisFunc%
   NumPut(RefCount := NumGet(IREOleCB + RefOffset, "UInt") + 1, IREOleCB + RefOffset, "UInt")
   Return RefCount
}
; --------------------------------------------------------------------------------------------------------------------------------
; IUnknown::Release
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_Release(IREOleCB) {
   Static RefOffset := A_PtrSize * 18
        , HeapOffset := A_PtrSize * 19
   OutputDebug, %A_ThisFunc%
   NumPut(RefCount := NumGet(IREOleCB + RefOffset, "UInt") - 1, IREOleCB + RefOffset, "UInt")
   If (RefCount = 0) {
      Heap := NumGet(IREOleCB + HeapOffset, "UPtr")
      DllCall("HeapDestroy", "Ptr", Heap)
   }
   Return RefCount
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::GetNewStorage
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_GetNewStorage(IREOleCB, IStoragePtr) {
   OutputDebug, %A_ThisFunc%
   ; msdn.microsoft.com/en-us/library/windows/desktop/aa378977(v=vs.85).aspx
	If !(HR := DllCall("Ole32.dll\CreateILockBytesOnHGlobal", "Ptr", 0, "Int", 1, "PtrP", ILockBytes)) {
      ; msdn.microsoft.com/en-us/library/windows/desktop/aa380324(v=vs.85).aspx
      ; STGM_READWRITE = 0x02, STGM_SHARE_EXCLUSIVE = 0x10, STGM_CREATE = 0x1000
   	If (HR := DllCall("Ole32.dll\StgCreateDocfileOnILockBytes", "Ptr", ILockBytes, "UInt", 0x1012, "UInt", 0, "PtrP", IStorage))
         ObjRelease(ILockBytes)
      Else
         NumPut(IStorage, IStoragePtr + 0, "UPtr")
   }
   Return HR
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::GetInPlaceContext - not implemented
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_GetInPlaceContext(IREOleCB, Frame, Doc, FrameInfo) {
   OutputDebug, %A_ThisFunc%
   Return 0x80004001 ; E_NOTIMPL
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::ShowContainerUI - not implemented
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_ShowContainerUI(IREOleCB, Show) {
   OutputDebug, %A_ThisFunc%
   Return 0x80004001 ; E_NOTIMPL
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::QueryInsertObject - returns S_OK
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_QueryInsertObject(IREOleCB, CLSID, STG, CP) {
   OutputDebug, %A_ThisFunc%
   Return 0 ; S_OK
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::DeleteObject - returns S_OK
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_DeleteObject(IREOleCB, OleObj) {
   OutputDebug, %A_ThisFunc%
   Return 0 ; S_OK
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::QueryAcceptData - returns S_OK
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_QueryAcceptData(IREOleCB, DataObj, Format, Operation, Really, MetaPic) {
   OutputDebug, %A_ThisFunc%
   Return 0 ; S_OK
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::ContextSensitiveHelp - not implemented
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_ContextSensitiveHelp(IREOleCB, EnterMode) {
   OutputDebug, %A_ThisFunc%
   Return 0x80004001 ; E_NOTIMPL
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::GetClipboardData - not implemented
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_GetClipboardData(IREOleCB, CharRange, Operation, DataObj) {
   OutputDebug, %A_ThisFunc%
   Return 0x80004001 ; E_NOTIMPL
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::GetDragDropEffect - returns S_OK
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_GetDragDropEffect(IREOleCB, Drag, KeyState, Effect) {
   OutputDebug, %A_ThisFunc%
   Return 0 ; S_OK
}
; --------------------------------------------------------------------------------------------------------------------------------
; IRichEditOleCallback::GetContextMenu - not implemented
; --------------------------------------------------------------------------------------------------------------------------------
IREOleCB_GetContextMenu(IREOleCB, SelType, OleObj, CharRange, HMENU) {
	;PUT YOUR  CONTEXT MNU HERE
	;Menu, RN_ContextMenu, Show
   ; OutputDebug, %A_ThisFunc%
   Return 0x80004001 ; E_NOTIMPL
}
Enjoy! ;)

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

by DigiDon » 10 Feb 2018, 11:50

Haa, interesting ! ;)

But now you can use my function above to have the number of columns and row you want directly.

You can put two inputbox to ask for value for example or directly use the interface I plan to introduce:
[GUI] Grid selection GUI

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

by moefr01 » 09 Feb 2018, 15:52

DigiDon... sorry for misunderstanding, here is the explanation:
First I created a new rtf-file with inserted tables (<clipboard<Word), saved it locally and at least used the function FileInsert of Poor Man‘s Rich Edit for that tables.rtf, added a button for further use. ;)

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

by DigiDon » 09 Feb 2018, 08:56

Hi moefr01,

Not sure what you mean by "out of word" and "linked with a button".
Could you elaborate?
What are you trying to achieve?

Anyway I have investigated a bit more tables.
There are no code implementation of an Insert Column function that I could find, which is really a pitty...

But I've figured out how you can insert an RFT table of x rows and y columns programmaticaly.
The problem is as I said I found no way of inserting a new column afterwards, not even speaking of merging cells.
You can nevertheless add new rows with the TAB key.
Image

Code: Select all

RN_InsertTable:
;3 columns, 4 rows, 3 centimeters of cell width 
RN_InsertRTFTable(RE2,3,4,3)
return

RN_InsertRTFTable(REObj,P_Cols,P_Rows,P_WidthCM) {
global
local rtfTable,WidthTwips
WidthTwips:=Round(P_WidthCM/2.54*1440)
	rtfTable := "{\rtf1\par"
	loop % P_Rows
		{
		rtfTable .= "\trowd\trgaph30"
		loop % P_Cols
		rtfTable .= "\cellx" WidthTwips * A_Index
		loop % P_Cols
			{
			rtfTable .= "\pard\intbl "
			rtfTable .= "\cell"
			}
		rtfTable .= "\row"
		}
	rtfTable .= "\par}"
	REObj.SetText(rtfTable,["SELECTION"])
}
More interestingly, I have prototyped a way you can create an Excel table of x rows and y columns that will be embedded into the RichEdit.
So the content is displayed directly, and on double-clic you can edit the table in Excel and the preview will be updated.
Image
In case anyone's is interested here is how the code looks like:

Code: Select all

RN_InsertTable:
	;Creates a new excel temp file in the background using COM
	xl:=ComObjCreate("Excel.Application"),xl.Visible:=false
	wb:=xl.Workbooks.Add()
	;Number of columns and rows (which can come as function parameters of course)
	ColumnNumber:=4
	RowNumber:=3
	;Populate the cells top and left so that it RichEdit will display the desired table
	loop % ColumnNumber
		{
		AA_Index:=A_Index
		xl.Cells(1,A_Index).Value := "Column"
		}
	loop % RowNumber
	xl.Cells(A_Index,1).Value := "Rows"
	wb.SaveAs(A_ScriptDir "\TempTable.xlsx")
	wb.Close()
	xl.Quit()
	;INSERT AS OLE OBJECT (not yet implemented officially in the class)
	RN_InsertObject(RE2.HWND, A_ScriptDir "\TempTable.xlsx")
	;DELETE the temp file: we don't need it anymore because it was embbeded
	FileDelete, % A_ScriptDir "\TempTable.xlsx"
return

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

by moefr01 » 08 Feb 2018, 12:34

Due to the fact that I'm terribly short of time... found another work-around for inserting tables: insert a rtf-file with predefined tables out of word and linked with a button/shortcut in the GUI.
...works fine!
I'm curious about DigiDon's further devs :) :?:

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

by DigiDon » 05 Feb 2018, 05:27

Hello moefr01
Yes I have made advancements on the mentioned improvements
See RichEdit : New Features to All
so I will be creating a new topic with improved class in the following days.

About tables I was wondering too.
The thing is it seems table manipulation will be extremely complicated to rely on RichEdit capabilities.

The biggest improvement I've made is that the RichEdit class will supports all OLE objects meaning you can import any file in a note and edit it in the appropriate program.
I think the better approch is to embed tables and work on them from Excel which is great at what it does.

See This preview
The only bad point for now is I have been unable to show the preview of the table as in this example direclty by dragging an excel file.
When I inserted with Word and then displayed it in AHK it was working fine though so I will try to investigate later why.
Edit: Might be some info here : REOleCb.cpp

The rest of this post will be used for reference

Important point is that a lot of features and capabilities depend on the version of the RichEdit control you are using.
As this class is intended to work for most people it will concentrate on the RichEdit 4.1 version which is shipped with Windows 7.
Newer versions of window ships with newer version of the controls especially with newer version of office dll that you could use.
A list I have found here : RichEdit versions
The latest version being RichEdit 8.0 which apparently have new methods for tables RichEdit 8.0 TOM Table Interfaces and other improvements

It seems ITextRow interface can also manipulate tables in some ways.
I think RichEdit 4.1 has some table capabilites referenced here.

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

by moefr01 » 04 Feb 2018, 09:35

thx just me for this awesome class... :clap:
hope DigiDon will continue that project properly to answer extraordinary questions from the community.
So, here's my first one:
Starting your GUI, I paste a WordPad/Word-table via clipboard successfully. Resizing the table-cells works fine, but is there any possibility to merge/unmerge cells (like Word does)???

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

by DigiDon » 27 Jan 2018, 10:12

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

by DigiDon » 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

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

by just me » 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.

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

by DigiDon » 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.

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

by DigiDon » 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 !

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

by ahklearner » 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

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

by just me » 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
   }

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

by a_ber » 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

Top