Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

cRichEdit - Standard RichEdit control for AutoHotkey scripts


  • Please log in to reply
110 replies to this topic
casano
  • Members
  • 6 posts
  • Last active: Nov 16 2007 07:53 AM
  • Joined: 14 Nov 2007
Thanks for that great piece of software! For my special purpose I need word wrap (as others did). Here is a quick & dirty solution:

In cGUI.ahk immediately after

If (ErrorLevel != 0 OR _ctrlID = 0)
Return "ERROR: Error creating control" . ErrorLevel . "/" . A_LastError

add

DllCall("SendMessage", "UInt", _ctrlID, "UInt", 0x448, "UInt", "0", "UInt", "0") ; EM_SETTARGETDEVICE

This works for me, but corrupt will know better, how to do it the clean way.

ezuk
  • Members
  • 149 posts
  • Last active: Jan 02 2013 08:54 AM
  • Joined: 04 Jun 2005
Nice control!

How do I make the scroll bars disappear? I can't even make them disappear when there's nothing to scroll. I want them to disappear completely, even if there's something to scroll. (And I don't want multi-line...)

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Thanks for the code suggestion casano :D . I'll have a look.

ezuk, the scrollbars are part of the default style used to create the control. Same with multi-line. I'll look into adding a function to change a few style options to make things a bit more user friendly :) . Thanks

Fuco
  • Members
  • 49 posts
  • Last active: Oct 24 2008 06:21 PM
  • Joined: 21 Mar 2006
how can i make it read only ? and also is there a function that will jump to the end of doc (+new line) ? so i can just append stuff at the end ( imagine something like IRC log or whatever... )

maybe add function addline() to append text to the end of doc.

btw thanx for this :p

EDIT: Ok i know how to make it readonly, just add 0x800 style and its ok :p so now i need jump to the end function :p
RegExReplace("C:\Program Files\AutoHotkey", "(^C)(?=\W).{4}((?i)[GOD])\w{1,4}\s(\D)(?:\w+)*\\(?3)(u|o).*?(k).*" , "$3$4$l1$5$2")

veio
  • Guests
  • Last active:
  • Joined: --
hello,
nice object, but to add the richedit to another gui window does not work.
Gui, 3:Show, +hide  H550 W550,HH Converter

If A_OSVersion = WIN_95
  cGUI("3:Add", REdit1, 10, 40, 480, 450, "RICHEDIT")
Else
  cGUI("3:Add", REdit1, 10, 40, 480, 450, "RichEdit20A")
cRichEdit(REdit1, "FileOpen", (A_ScriptDir . "\test.rtf"))

Gui, 3:Show
This adds the richedit to the main gui window. What am i doing wrong?

veio

veio
  • Guests
  • Last active:
  • Joined: --
maybe i found the error:
in cGUI.ahk at "if(_Action0="3")" it must be "else if" i guess.

JDP
  • Guests
  • Last active:
  • Joined: --
Whe doesn't this work?
;TRY TO PUT RTF UNDER A TAB
Gui,add,Tab2,,one|two
Gui,Tab,two
GuiHwnd := WinExist()
cGUI("1:Add:%GuiHwnd%", REdit1, GMarginW, GRTFeditT, GRTFeditW, GRTFeditH, RTFeditor)

Note:
If A_OSVersion = WIN_95
  RTFeditor:="RICHEDIT"
Else
  RTFeditor:="RichEdit20A"


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
I'm pretty sure you need to specify the HWND of the TAB. I'll see if I can put an example together... :)

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Updated to version 0.08 beta :)

- fixed a bug in cGUI that prevented specifying a HWND for the control's parent
- added an example script for adding the control to an AutoHotkey Tab control to the download (link on the first page).



Here's one method for adding the RichEdit control to a Tab (version 0.08 or higher required):
Gui, Add, Tab, x10 y10 w380 h380 +0x2C2, Tab1|Tab2|Tab3
Gui, Add, Button, w100 h30,This is a test
Gui, Add, Text,, Please go to tab 2 to see the RichEdit control
Gui, Tab, Tab2
Gui, Add, Button, w100 h30,Ok
Gui, Add, Picture, w320 h270 HwndREparent1

Gui, Add, Text,, This is another test control
Gui, Tab, Tab3
Gui, Add, Button, w100 h30,Cancel

If A_OSVersion = WIN_95
  cGUI("1:Add:" . REparent1, REdit1, 0, 0, 320, 270, "RICHEDIT")
Else
  cGUI("1:Add:" . REparent1, REdit1, 0, 0, 320, 270, "RichEdit20A")

cRichEdit(REdit1, "ReplaceSel",
(
"{\rtf1\ansi\ansicpg13312\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\fswiss\fprq2\fcharset0 Arial Black;}}{\colortbl ;\red0\green0\blue0;\red128\green128\blue128;\red255\green0\blue0;\red0\green0\blue255;\red0\green255\blue0;\red255\green0\blue255;}\viewkind4\uc1\pard\nowidctlpar\cf1\f0\fs20 .\cf2\f1 This is a test\cf3\f0\par\cf4\parTesting 1 2 3 4\par\par\cf5\fs56 Hello\cf4\fs20  \cf6\fs44 World\cf4\fs20   :) \par}
}"
))

Gui, Show, h400 w400, Tab Test
Return

GuiClose:
If (REdit1) 
  cRichEdit(REdit1, "Destroy")
Gui, %A_Gui%:Destroy
cGUI("FreeDlls", NULL)
ExitApp
Return

; comment the following #Include lines if you are using stdlib and have copied the required
; cGUI.ahk and cRichedit.ahk files to your stdlib directory

#Include cGUI.ahk
#Include cRichEdit.ahk
Posted Image

TodWulff
  • Members
  • 142 posts
  • Last active: Sep 15 2013 04:16 PM
  • Joined: 29 Dec 2007
corrupt (or someone else :)),

Can you please take a peek at my most recent request for assistance? I haven't gotten a response to it therein. Lexikos (via IRC) pointed me towards another thread, which has potential for being a means of resolution. While reading that, I came across this thread, which seems to be equally as exciting.

I attempted to and have successfully integrated the use of cRichEdit into my IDE project. It was actually pretty easy, once I got over the initial fear of breaking everything with changing one of the most important controls in my project.

Anyways, if you could offer input on how you might go about trying to address my needs, via the use of your tools, it would be greatly appreciated. TIA.

Take care.

-t
When replying, please feel free to address me as Tod. My AHK.net site...

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Hi TodWulff :) . There are likely a few methods that you could use to scroll to the bottom of the control. One method might be to use GetTextLength to get the number of characters in the control then use EXSETSEL to set the current selection to the number of characters in the control (start and end position both set to the number of characters in the control). You can test this method by using the commands in the Feature_Demo script that is included in the download.

Another method might be to send a <ctrl> + <end> keystroke to the control... There are a few other methods also... Since the control that gets added using the code here is a standard Windows RichEdit control (not modified - this code is just a wrapper), you will likely find that many of the other methods/functions that you find for use with Edit/RichEdit controls will likely work with this instance of the RichEdit control also.

TodWulff
  • Members
  • 142 posts
  • Last active: Sep 15 2013 04:16 PM
  • Joined: 29 Dec 2007
Thanks corrupt.

Maybe I confused the issue a bit. Yeah, the movement to the bottom of the control is not an issue.

What I am wondering how to accomplish is how do I keep the text in the displayed portion of the control static, while appending to the end of the text in the control...

Is this something that you think is do-able?

-t
When replying, please feel free to address me as Tod. My AHK.net site...

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Here's a subroutine that might not be exactly what you're looking for if you are adding to the control constantly at the end and trying to scroll and read through the results at the same time...

testadd:
  ; Get current scroll position and current selection/caret position
  curpos := cRichEdit(REdit1, "GETSCROLLPOS")
  cursel := cRichEdit(REdit1, "EXGETSEL")
  DllCall("LockWindowUpdate", "UInt", REdit1) ; stop refreshing the control
  ; move to the end of the control
  endpos := cRichEdit(REdit1, "GETTEXTLENGTH")
  cRichEdit(REdit1, "EXSETSEL", endpos, endpos)
  ; add text
  Loop, 200
    cRichEdit(REdit1, "ReplaceSel", "This is a test`r`n`r`ntesting 1 2 3 4 `r`n`r`na b c d ", true)
  ; set the scroll position and selection back to the previous values
  StringSplit, sxy, cursel, |
  cRichEdit(REdit1, "EXSETSEL", sxy1, sxy2)
  StringSplit, xy, curpos, |
  cRichEdit(REdit1, "SETSCROLLPOS", xy1, xy2)  
  DllCall("LockWindowUpdate", "UInt", 0) ; resume refreshing
  ControlFocus,, ahk_id %REdit1% 
Return


corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Updated to version 0.9

- added WordWrap option - Thanks casano

TodWulff
  • Members
  • 142 posts
  • Last active: Sep 15 2013 04:16 PM
  • Joined: 29 Dec 2007
Thanks corrupt - looks to be working with some minor tweaks.!.

I see in another post above where another user was able to set the control to read only with a style of 0x800. I've been struggling to implement this as I don't want the user to have the ability to alter the contents of the console window. Can you provide an example of the use of the 0x800 style in the cRichEdit Constructs?

Take care. Thanks again!

-t

BTW, does the WordWrap'g you just added, negate the need for, and subsequently suppress, the horizontal scroll bar, when enabled? If not, you might want to consider it...
When replying, please feel free to address me as Tod. My AHK.net site...