RichEdit

This module allows you to create and programmatically set text properties in rich edit control.  Besides that, it contains functions that work with standard edit controls.  Each function contains description for which kind of control it can be used - any control supporting edit control interface (Edit, RichEdit, HiEdit...) or just rich edit control.

Summary
RichEditThis module allows you to create and programmatically set text properties in rich edit control.
AddCreate rich edit version 4.1 control.
AutoUrlDetectEnable, disable, or toggle automatic detection of URLs in the RichEdit control.
CanPasteDetermines whether an Edit control can paste a specified clipboard format.
CharFromPosGets information about the character closest to a specified point in the client area of the Edit control.
ClearSend to an Edit control or combo box to delete (clear) the current selection.
ConvertConvert twips to pixels or vice-versa.
CopyCopy selection of the Edit control.
CutCut selection from the Edit control.
FindTextFind desired text in the Edit control.
FindWordBreakFinds the next word break in rich edit conttrol, before or after the specified character position or retrieves information about the character at that position.
FixKeysFix Tab and Esc key handling in rich edit control.
GetLineGet the text of the desired line from an Edit control.
GetLineCountGets the number of lines in a multiline Edit control.
GetOptionsGet the options for a rich edit control.
GetCharFormatDetermines the character formatting in a rich edit control.
GetRedoDetermine whether there are any actions in the rich edit control redo queue, and optionally retrieve the type of the next redo action.
GetModifyGets the state of the modification flag for the Edit control.
GetParaFormatRetrieves the paragraph formatting of the current selection in a rich edit control.
GetRectGets the formatting rectangle of the Edit control.
GetSelRetrieve the starting and ending character positions of the selection in a rich edit control.
GetTextRetrieves a specified range of characters from a rich edit control.
GetTextLengthCalculates text length in various ways for a rich edit control.
GetUndoDetermine whether there are any actions in the Edit control undo queue, and optionally retrieve the type of the next undo action.
HideSelectionHides or shows the selection in a rich edit control.
LineFromCharDetermines which line contains the specified character in a rich edit control.
LineIndexReturns the character index of the first character of a specified line in an Edit control.
LineLengthReturns the length of a line in an Edit control.
LineScrollScrolls the text in the Edit control.
LimitTextSets an upper limit to the amount of text the user can type or paste into a rich edit control.
PastePaste clipboard into the Edit control.
PasteSpecialPastes a specific clipboard format in a rich edit control.
PosFromCharGets the client area coordinates of a specified character in an Edit control.
RedoDo redo operation.
ReplaceSelReplace selection with desired text in the Edit control.
SaveSave the content of the rich edit control using RT format.
ScrollCaretScroll content of Edit control until caret is visible.
ScrollPosObtain the current scroll position, or tell the rich edit control to scroll to a particular point.
SelectionTypeDetermines the selection type for a rich edit control.
SetBgColorSets the background color for a rich edit control.
SetCharFormatSet character formatting in a rich edit control.
SetEventsSet notification events.
SetFontSizeSets the font size for the selected text in the rich edit control.
SetModifySets or clears the modification flag for an edit control.
SetOptionsSets the options for a rich edit control.
PageRotateRotate page.
SetParaFormatSets the paragraph formatting for the current selection in a rich edit control.
SetEditStyleSets the current edit style flags.
SetSelSelects a range of characters or Component Object Model (COM) objects in a rich edit control.
SetTextSet text from string or file in rich edit control using either rich text or plain text.
SetUndoLimitSet the maximum number of actions that can stored in the undo queue of the rich edit control.
ShowScrollBarShows or hides scroll bars for Edit control.
TextModeGet or set the current text mode of a rich edit control.
WordWrapSet word wrap mode in rich edit control.
ZoomSets the zoom ratio anywhere between 1/64 and 64.
UndoSend message to Edit control to undo the next action in the control’s undo queue & optionally empty the undo buffer by resetting the undo flag.
About

Add

RichEdit_Add(HParent,  
X = "",
Y = "",
W = "",
H = "",
Style = "",
Text = "")

Create rich edit version 4.1 control.  (requires at least Windows XP SP1)

Parameters

HParentHandle of the parent of the control.
X..HPosition.
StyleWhite space separated list of control styles.  Any integer style or one of the style keywords (see below).  Invalid styles are skipped.  “MULTILINE WANTRETURN VSCROLL” by default.
TextControl text.  Styles:
DISABLENOSCROLLDisables scroll bars instead of hiding them when they are not needed.
BORDERDisplays the control with a sunken border style so that the rich edit control appears recessed into its parent window.
HIDDENDon’t show the control.
VSCROLLEnble vertical scroll bar.
HSCROLLEnable horizontal scroll bar.  If this style is present control starts with wrap mode deactivated.  Otherwise, wrap mode is active.
SCROLLEnable both scroll bars.
AUTOHSCROLLAutomatically scrolls text to the right by 10 characters when the user types a character at the end of the line.  When the user presses the ENTER key, the control scrolls all text back to position zero.
AUTOVSCROLLAutomatically scrolls text up one page when the user presses the ENTER key on the last line.
CENTERCenters text in a single-line or multiline edit control.
LEFTLeft aligns text.
MULTILINEDesignates a multiline edit control.  The default is single-line edit control.
NOHIDESELNegates the default behavior for an edit control.  The default behavior hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus.  If you specify NOHIDESEL, the selected text is inverted, even if the control does not have the focus.
NUMBERAllows only digits to be entered into the edit control.
PASSWORDDisplays an asterisk (*) for each character typed into the edit control.  This style is valid only for single-line edit controls.
READONLYPrevents the user from typing or editing text in the edit control.
RIGHTRight aligns text in a single-line or multiline edit control.
SELECTIONBARWhen set, there is small left margin (wider than default) where cursor changes to right-up arrow allowing full line(s) selection.  This style also requires use of MULTILINE style.
WANTRETURNSpecifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiline edit control in a dialog box.  If you do not specify this style, pressing the ENTER key has the same effect as pressing the dialog box’s default push button.  This style has no effect on a single-line edit control.

Returns

Control’s handle or 0.  Error message on problem.

Example

Gui, +LastFound
hwnd := WinExist()
hRichEdit := RichEdit_Add(hwnd, 5, 5, 200, 300)
Gui, Show, w210 h310

AutoUrlDetect

RichEdit_AutoUrlDetect(HCtrl,  
Flag = "")

Enable, disable, or toggle automatic detection of URLs in the RichEdit control.

Parameters

FlagSpecify true to enable automatic URL detection or false to disable it.  Specify ”^” to toggle its current state.  Omit to only return current state without any change.

Returns

If auto-URL detection is active, the return value is 1.  If auto-URL detection is inactive, the return value is 0.

Example

MsgBox, % RichEdit_AutoUrlDetect( hRichEdit, true )
MsgBox, % RichEdit_AutoUrlDetect( hRichEdit, "^" )
MsgBox, % "Current state: " RichEdit_AutoUrlDetect( hRichEdit )

CanPaste

RichEdit_CanPaste(hEdit,  
ClipboardFormat = 0x1)

Determines whether an Edit control can paste a specified clipboard format.

Parameters

ClipboardFormatSpecifies the Clipboard Formats to try.  To try any format currently on the clipboard, set this parameter to zero.  The default is 0x1 (CF_TEXT).

Returns

True if the clipboard format can be pasted otherwise false.

Remarks

For additional information on clipboard formats, see the following: http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx

Related

Paste, PasteSpecial

Example

If RichEdit_CanPaste( hRichEdit, 0 )
  RichEdit_Paste( hRichEdit )
Else
  MsgBox, Cannot paste your clipboard into control..

CharFromPos

RichEdit_CharFromPos(hEdit,
X,
Y)

Gets information about the character closest to a specified point in the client area of the Edit control.

Parameters

X, YThe coordinates of a point in the Edit control’s client area relative to the upper-left corner of the client area.

Returns

The character index of the specified point or the character index to the last character if the given point is beyond the last character in the control.

Clear

RichEdit_Clear(hEdit)

Send to an Edit control or combo box to delete (clear) the current selection.

Remarks

To delete the current selection and place the deleted content on the clipboard, use the Cut operation.

Related

Cut, Copy, Paste

Convert

RichEdit_Convert(Input,  
Direction = )

Convert twips to pixels or vice-versa.

Parameters

InputTwips (Input>0) or pixels (Input<0).
Direction0 (default) or 1.  Pixels are not always square (the height and width are not the same).  Therefore, it is necessary to pass in the desired “direction” to use, horizontal (0) or vertical (1).  Returns: Rounded value.

Copy

RichEdit_Copy(hEdit)

Copy selection of the Edit control.

Related

Cut, Clear, Paste

Cut

RichEdit_Cut(hEdit)

Cut selection from the Edit control.

Related

Copy, Clear, Paste

FindText

RichEdit_FindText(hEdit,  
Text,  
CpMin = 0,
CpMax = -1,
Flags = "UNICODE")

Find desired text in the Edit control.

Parameters

TextText to be searched for.
CpMinStart searching at this character position.  By default 0.
CpMaxEnd searching at this character position.  When searching forward, a value of –1 extends the search range to the end of the text.
FlagsSpace separated combination of search flags.  See below.

Flags

WHOLEWORDIf set, the operation searches only for whole words that match the search string.  If not set, the operation also searches for word fragments that match the search string.
MATCHCASEIf set, the search operation is case-sensitive.  If not set, the search operation is case-insensitive.
DOWNRich Edit only: If set, the search is from the end of the current selection to the end of the document.  If not set, the search is from the end of the current selection to the beginning of the document.
UNICODETransforms Text into the Unicode charset before searching for it.  Returns: The zero-based character position of the next match, or -1 if there are no more matches.

Remarks The CpMin member always specifies the starting-point of the search, and CpMax specifies the end point.  When searching backward, CpMin must be equal to or greater than CpMax.

Example

^f::
  RichEdit_HideSelection( hRichEdit, false )
  Dlg_Find( hwnd, "OnFind", "d" )
return

OnFind(Event, Flags, FindText, ReplaceText)  {
  global hRichEdit

  IfNotEqual, Event, F,  return
  RichEdit_GetSel(hRichEdit, min, max)
  word := InStr(Flags,"w") ? " WHOLEWORD" : ""
  case := InStr(Flags,"c") ? " MATCHCASE" : ""
  InStr( Flags, "d" ) ? (pos:=max+1 , direction:=" DOWN")
                      : (pos:=max-1)

  ; search control for word
  pos:=RichEdit_FindText(hRichEdit,FindText,pos,-1,"unicode" direction word case)

  ; highlight found match
  if pos != -1
      RichEdit_SetSel(hRichEdit, pos, pos+StrLen(FindText))

  Else
    MsgBox, no matches found..
}
return

FindWordBreak

RichEdit_FindWordBreak(hCtrl,  
CharIndex,  
Flag = "")

Finds the next word break in rich edit conttrol, before or after the specified character position or retrieves information about the character at that position.

Parameters

CharIndexZero-based character starting position.
FlagOne of the flags list below.

Flag

CLASSIFYReturns the character class and word-break flags of the character at the specified position.
ISDELIMITERReturns true if the character at the specified position is a delimiter, or false otherwise.
LEFTFinds the nearest character before the specified position that begins a word.
LEFTBREAKFinds the next word end before the specified position.  This value is the same as PREVBREAK.
MOVEWORDLEFTFinds the next character that begins a word before the specified position.  This value is used during CTRL+LEFT ARROW key processing.
MOVEWORDRIGHTFinds the next character that begins a word after the specified position.  This value is used during CTRL+right key processing.
RIGHTFinds the next character that begins a word after the specified position.
RIGHTBREAKFinds the next end-of-word delimiter after the specified position.  This value is the same as NEXTBREAK.

Returns

The message returns a value based on the wParam parameter.

  • CLASSIFY - Returns the character class and word-break flags of the character at the specified position.
  • ISDELIMITER - Returns true if the character at the specified position is a delimiter, otherwise it returns false.
  • Other - Returns the character index of the word break.

FixKeys

RichEdit_FixKeys(hCtrl)

Fix Tab and Esc key handling in rich edit control.

Returns

True or false.

Remarks

Whenever you press Escape in a multiline edit control it sends a WM_CLOSE message to its parent.  Both the regular edit control and the rich edit control have this problem.  This is by Microsoft design.  There is also similar undesired behavior for {Tab} key which is used by the system to navigate over controls with “tabstop” flag.  RichEdit is designed to use ^{Tab} instead.  This function subclasses the control to prevent such behavior.

However, before using this function be sure to know what subclassing is and what kind of effects it may introduce to your particular script.  There is also other method to solve this problem via hotkey handling while rich edit control has focus.

Reference

GetLine

RichEdit_GetLine(hEdit,  
LineNumber = -1)

Get the text of the desired line from an Edit control.

Parameters

LineNumberZero-based index of the line.  -1 means current line.

Returns

The return value is the text.  The return value is empty string if the line number specified by the line parameter is greater than the number of lines in the Edit control.

Related

GetText, LineIndex, LineLength

GetLineCount

RichEdit_GetLineCount(hEdit)

Gets the number of lines in a multiline Edit control.

Returns

The return value is an integer specifying the total number of text lines in the multiline edit control or rich edit control.  If the control has no text, the return value is 1.  The return value will never be less than 1.

Remarks

The function retrieves the total number of text lines, not just the number of lines that are currently visible.  If the Wordwrap feature is enabled, the number of lines can change when the dimensions of the editing window change.

Related

GetTextLength, LineLength

GetOptions

RichEdit_GetOptions(hCtrl)

Get the options for a rich edit control.

Remarks

See SetOptions for details.

GetCharFormat

RichEdit_GetCharFormat( hCtrl,  
ByRef Face = "",
ByRef Style = "",
ByRef TextColor = "",
ByRef BackColor = "",
 Mode = "SELECTION")

Determines the character formatting in a rich edit control.

Parameters

FaceOptional byref parameter will contain the name of the font.
StyleOptional byref parameter will contain a space separated list of styles.  See SetCharFormat for list of styles.
TextColorText forground color.  If starts with “-” the color is AUTOCOLOR.
BackColorText background color.  If starts with “-” the color is AUTOCOLOR.
ModeIf empty, this optional parameter retrieves the formatting to all text in the control.  Otherwise, pass “SELECTION” (default) to get formatting of the current selection.  If the selection is empty, the function will get the character of the insertion point.

Remarks

Function will get the attributes of the first character.

Related

SetCharFormat, SetBgColor

Example

RichEdit_GetCharFormat(hRichEdit, face, style, color)
MsgBox, Face = %Face% `nstyle = %style%  `ncolor = %color%

GetRedo

RichEdit_GetRedo( hCtrl,  
ByRef name = "-")

Determine whether there are any actions in the rich edit control redo queue, and optionally retrieve the type of the next redo action.

Parameters

nameThis optional parameter is the name of the variable in which to store the type of redo action, if any.

Name Types

UNKNOWNThe type of undo action is unknown.
TYPINGTyping operation.
DELETEDelete operation.
DRAGDROPDrag-and-drop operation.
CUTCut operation.
PASTEPaste operation.

Returns

If there are actions in the control redo queue, the return value is a nonzero value.  If the redo queue is empty, the return value is zero.

Related

Redo, GetUndo, Undo, SetUndoLimit

Example

If RichEdit_GetRedo( hRichEdit, name )
  MsgBox, The next redo is a %name% type
Else
  MsgBox, Nothing left to redo.

GetModify

RichEdit_GetModify(hEdit)

Gets the state of the modification flag for the Edit control.  The flag indicates whether the contents of the control has been modified.

Returns

True if the content of Edit control has been modified, false otherwise.

Related

SetModify, Save

GetParaFormat

Retrieves the paragraph formatting of the current selection in a rich edit control.  (*** not implemented ***)

GetRect

RichEdit_GetRect( hEdit,  
ByRef Left = "",
ByRef Top = "",
ByRef Right = "",
ByRef Bottom = "")

Gets the formatting rectangle of the Edit control.

Parameters

Left..BottomOutput variables, can be omitted.

Returns

Space separated rectangle.

GetSel

RichEdit_GetSel( hCtrl,  
ByRef cpMin = "",
ByRef cpMax = "")

Retrieve the starting and ending character positions of the selection in a rich edit control.

Parameters

cpMinThe optional name of the variable in which to store the character position index immediately preceding the first character in the range.
cpMinThe optional name of the variable in which to store the character position index immediately following the last character in the range.

Returns

Returns cpMin.  If there is no selection this is cursor position.

Related

GetText, GetTextLength, SetSel, SetText, HideSelection, LineFromChar

GetText

RichEdit_GetText(HCtrl,  
CpMin = "-",
CpMax = "-",
CodePage = "")

Retrieves a specified range of characters from a rich edit control.

Parameters

CpMinBeginning of range of characters to retrieve.
CpMaxEnd of range of characters to retrieve.
CodePageIf UNICODE or U, this optional parameter will use unicode code page in the translation.  Otherwise it will default to using ansi.  (*** needs rework ***)

Note

If the CpMin and CpMax are omitted, the current selection is retrieved.  The range includes everything if CpMin is 0 and CpMax is –1.

Returns

Returns the retrieved text.

Related

GetSel, GetLine, GetTextLength, SetText, SetSel, FindText

Example

MsgBox, % RichEdit_GetText( hRichEdit ) ; get current selection
MsgBox, % RichEdit_GetText( hRichEdit, 0, -1 ) ; get all
MsgBox, % RichEdit_GetText( hRichEdit, 4, 10 ) ; get range

GetTextLength

RichEdit_GetTextLength(hCtrl,  
Flags = 0,
CodePage = "")

Calculates text length in various ways for a rich edit control.

Parameters

flagSpace separated list of one or more options.  See below list.
codepageIf UNICODE or U, this optional parameter will use unicode code page in the translation.  Otherwise it will default to using ansi.

Flag Options

DEFAULTReturns the number of characters.  This is the default.
USECRLFComputes the answer by using CR/LFs at the end of paragraphs.
PRECISEComputes a precise answer.  This approach could necessitate a conversion and thereby take longer.  This flag cannot be used with the CLOSE flag.
CLOSEComputes an approximate (close) answer.  It is obtained quickly and can be used to set the buffer size.  This flag cannot be used with the PRECISE flag.
NUMCHARSReturns the number of characters.  This flag cannot be used with the NUMBYTES flag.
NUMBYTESReturns the number of bytes.  This flag cannot be used with the NUMCHARS flag.

Returns

If the operation succeeds, the return value is the number of TCHARs in the edit control, depending on the setting of the flags.  If the operation fails, the return value is blank.

Remarks

This message is a fast and easy way to determine the number of characters in the Unicode version of the rich edit control.  However, for a non-Unicode target code page you will potentially be converting to a combination of single-byte and double-byte characters.

Related

LineLength, LimitText, GetSel

Example

MsgBox, % "DEFAULT  = " RichEdit_GetTextLength(hRichEdit, "DEFAULT" )  "`n"
        . "USECRLF  = " RichEdit_GetTextLength(hRichEdit, "USECRLF" )  "`n"
        . "PRECISE  = " RichEdit_GetTextLength(hRichEdit, "PRECISE" )  "`n"
        . "CLOSE    = " RichEdit_GetTextLength(hRichEdit, "CLOSE" )    "`n"
        . "NUMCHARS = " RichEdit_GetTextLength(hRichEdit, "NUMCHARS" ) "`n"
        . "NUMBYTES = " RichEdit_GetTextLength(hRichEdit, "NUMBYTES" ) "`n"

GetUndo

RichEdit_GetUndo( hCtrl,  
ByRef Name = "-")

Determine whether there are any actions in the Edit control undo queue, and optionally retrieve the type of the next undo action.

Parameters

NameOptional byref parameter will contain the type of undo action, if any.

Types

UNKNOWNThe type of undo action is unknown.
TYPINGTyping operation.
DELETEDelete operation.
DRAGDROPDrag-and-drop operation.
CUTCut operation.
PASTEPaste operation.

Returns

If there are actions in the control undo queue, the return value is a nonzero value.  If the undo queue is empty, the return value is zero.

Related

Undo, SetUndoLimit, GetRedo, Redo

Example

If RichEdit_GetRedo( hRichEdit, name )
  MsgBox, The next redo is a %name% type
Else MsgBox, Nothing left to redo.

HideSelection

RichEdit_HideSelection(hCtrl,  
State = true)

Hides or shows the selection in a rich edit control.

Parameters

StateTrue or false.

Remarks

This function is noticeable when it is set to false and the rich edit control isn’t the active control or window.  The example included in FindText demonstrates use.

Related

SetSel, GetSel

LineFromChar

RichEdit_LineFromChar(hCtrl,  
CharIndex = -1)

Determines which line contains the specified character in a rich edit control.

Parameters

CharIndexZero-based integer index of the character.  -1 (default) means current line.

Returns

Zero-based index of the line.

Related

LineIndex, GetLineCount

LineIndex

RichEdit_LineIndex(hEdit,  
LineNumber = -1)

Returns the character index of the first character of a specified line in an Edit control.

Parameters

LineNumberLine number for which to retreive character index.  -1 (default) means current line.

Returns

The character index of the line specified, or -1 if the specified line number is greater than the number of lines.

Related

LineLength, LineFromChar, GetLine, GetLineCount

LineLength

RichEdit_LineLength(hEdit,  
LineNumber = -1)

Returns the length of a line in an Edit control.

Parameters

LineNumberLine number for which to retreive line length.  -1 (default) means current line.

Returns

The length (in characters) of the line.

Related

GetTextLength, LineIndex, LineFromChar

LineScroll

RichEdit_LineScroll(hEdit,  
XScroll = 0,
YScroll = 0)

Scrolls the text in the Edit control.

Parameters

XScrollThe number of characters to scroll horizontally.  Use a negative number to scroll to the left and a positive number to scroll to the right.
YScrollThe number of lines to scroll vertically.  Use a negative number to scroll up and a positive number to scroll down.  Remarks: This message does not move the caret.  This function can be used to scroll horizontally past the last character of any line.

LimitText

RichEdit_LimitText(hCtrl,  
txtSize = )

Sets an upper limit to the amount of text the user can type or paste into a rich edit control.

Parameters

txtSizeSpecifies the maximum amount of text that can be entered.  If this parameter is zero, the default maximum is used, which is 64K characters.  A Component Object Model (COM) object counts as a single character.

Returns

This function does not return a value.

Remarks

Before LimitText is called, the default limit to the amount of text a user can enter is 32,767 characters.

Paste

RichEdit_Paste(hEdit)

Paste clipboard into the Edit control.

Related

CanPaste, PasteSpecial, Cut, Copy, Clear

PasteSpecial

RichEdit_PasteSpecial(HCtrl,
Format)

Pastes a specific clipboard format in a rich edit control.

Parameters

FormatOne of the clipboard formats.  See http://msdn.microsoft.com/en-us/library/bb774214(VS.85).aspx

Related

CanPaste, Paste

PosFromChar

RichEdit_PosFromChar( hEdit,
 CharIndex,
ByRef X,
ByRef Y)

Gets the client area coordinates of a specified character in an Edit control.

Parameters

CharIndexThe zero-based index of the character.
X, YThese parameters, which must contain valid variable names, are used to return the x/y-coordinates of a point in the control’s client relative to the upper-left corner of the client area.

Remarks

If CharIndex is greater than the index of the last character in the control, the returned coordinates are of the position just past the last character of the control.

Redo

RichEdit_Redo(hEdit)

Do redo operation.

Returns

True if the Redo operation succeeds, false otherwise.

ReplaceSel

RichEdit_ReplaceSel(hEdit,  
Text = "")

Replace selection with desired text in the Edit control.

Parameters

TextText to replace selection with.

Save

RichEdit_Save(hCtrl,  
FileName = "")

Save the content of the rich edit control using RT format.

Parameters

FileNameFile name to save RTF file to.  If omitted, function will return content.

Related

GetModify, SetModify

Example

If !RichEdit_GetModify( hRichEdit )  {
  MsgBox, No changes detected
  return
}

RichEdit_Save( hRichEdit, file )
RichEdit_SetModify( hRichEdit, false )
MsgBox, File has been saved

ScrollCaret

RichEdit_ScrollCaret(hEdit)

Scroll content of Edit control until caret is visible.

ScrollPos

RichEdit_ScrollPos(HCtrl,  
PosString = "")

Obtain the current scroll position, or tell the rich edit control to scroll to a particular point.

Parameters

PosStringString specifying the x/y point in the virtual text space of the document, expressed in pixels.  (See example)

Returns

If posString is omitted, the return value is the current scroll position.

Related

ShowScrollBar, GetSel, LineFromChar, SetSel

Example

Msgbox, % "scroll pos = " RichRichEdit_ScrollPos( hRichEdit )
RichRichEdit_ScrollPos( hRichEdit , "7/22" )

SelectionType

RichEdit_SelectionType(hCtrl)

Determines the selection type for a rich edit control.

Returns

If the selection is not empty, the return value is a set of flags containing one or more of the following values: TEXT - Text.  OBJECT - At least one Component Object Model (COM) object.  MULTICHAR - More than one character of text.  MULTIOBJECT - More than one COM object.

Remarks

This message is useful during WM_SIZE processing for the parent of a bottomless rich edit control.

SetBgColor

RichEdit_SetBgColor(hCtrl,
Color)

Sets the background color for a rich edit control.

Parameters

ColorColor in RGB format (0xRRGGBB) if > 0 or BGR format if < 0.

Returns

Returns the previous background color in RGB format.

Related

SetCharFormat, GetCharFormat

Example

Dlg_Color( color, hRichEdit )
RichEdit_SetBgColor( hRichEdit, color )

RichEdit_SetBgColor( hRichEdit, 0xa9f874 )

SetCharFormat

RichEdit_SetCharFormat(HCtrl,  
Face = "",
Style = "",
TextColor = "",
BackColor = "",
Mode = "SELECTION")

Set character formatting in a rich edit control.

Parameters

FaceFont name.  Optional.
StyleSpace separated list of styles.  See below list.  Optional.
TextColorText foreground color.  Optional.
BackColorText backgrond color.  Optional.
ModeCharacter formatting that applies to the control.  If omitted, the function changes the default character formatting.  It can be one of the values given bellow.  Optional.

Styles

s<Num>Character size, usual AHK represntation (i.e. s12)
o<Num>Character offset from the baseline, in twips,.  If the value of this member is positive, the character is a superscript; if the value is negative, the character is a subscript.
AUTOBACKCOLORThe background color is the return value of GetSysColor(COLOR_WINDOW:=5).  If this flag is set, BackColor member is ignored.
AUTOCOLORThe text color is the return value of GetSysColor(COLOR_WINDOWTEXT:=8).  If this flag is set, the TextColor member is ignored.
BOLDCharacters are bold.
HIDDENCharacters are not displayed.
ITALICCharacters are italic.
LINKA rich edit control sends LINK notification messages when it receives mouse messages while the mouse pointer is over text with the LINK effect.
PROTECTEDCharacters are protected; an attempt to modify them will cause an PROTECTED notification message.
STRIKEOUTCharacters are struck out.
SUBSCRIPTCharacters are subscript.  The SUPERSCRIPT and SUBSCRIPT values are mutually exclusive.  For both values, the control automatically calculates an offset and a smaller font size.
SUPERSCRIPTCharacters are superscript.
UNDERLINECharacters are underlined.

Modes

DEFAULTChanges the formating for the default text in the control.  This is also the style used if you don’t specify valid style.
ALLApplies the formatting to all text in the control.
SELECTIONApplies the formatting to the current selection.  If the selection is empty, the character formatting is applied to the insertion point, and the new character format is in effect only until the insertion point changes.
WORDApplies the formatting to the selected word or words.  If the selection is empty but the insertion point is inside a word ,the formatting is applied to the word.

Returns

True or false.

Remarks

This function will fire up SELCHANGE message even if selection isn’t changed.

SetEvents

RichEdit_SetEvents(hCtrl,  
Handler = "",
Events = "selchange")

Set notification events.

Parameters

HandlerFunction that handles events.  If empty, any existing handler will be removed.
EventsWhite space separated list of events to monitor.

Handler

Result := Handler(hCtrl, Event, p1, p2, p3 )
hCtrlHandle of richedit control sending the event.
EventSpecifies event that occurred.  Event must be registered to be able to monitor it.
Col,RowCell coordinates.
DataNumeric data of the cell.  Pointer to string for textual cells and DWORD value for numeric.
ResultReturn 1 to prevent action.

Events

CHANGE: Sent when the user has taken an action that may have altered text in an edit control.  Sent after the system updates the screen.  (***)

DRAGDROPDONE: Notifies a rich edit control’s parent window that the drag-and-drop operation has completed.

  • P1 - Number of characters highlighted in drag-drop operation.
  • P2 - Beginning character position of range.
  • P3 - Ending character position of range.

DROPFILES: Notifies that the user is attempting to drop files into the control.

  • P1 - Number of files dropped onto rich edit control.
  • P2 - Newline delimited (`n) list of files dropped onto control.
  • P3 - Character position files were dropped onto within rich edit control.

KEYEVENTS: Notification of a keyboard or mouse event in the control.  To ignore the event, the handler function should return a nonzero value.  (*** needs redone)

  • P1 - Character position files were dropped onto within rich edit control.

MOUSEEVENTS,SCROLLEVENTS,LINK: A rich edit control sends these messages when it receives various messages, when the user clicks the mouse or when the mouse pointer is over text that has the LINK effect.  (*** expand usefulness)

PROTECTED: User is taking an action that would change a protected range of text.  To ignore the event, the handler function should return a nonzero value.

REQUESTRESIZE: This message notifies a rich edit control’s parent window that the control’s contents are either smaller or larger than the control’s window size.

  • P1 - Requested new size.

SELCHANGE: The current selection has changed.

  • P1 - Beginning character position of range.
  • P2 - Ending character position of range.
  • P3 - Selection type.

LINK: The hyperlink has been clicked.

  • P1 - LClick or RClick.
  • P2 - CpMin.
  • P3 - CpMax.

Returns

The previous event mask (number).

SetFontSize

RichEdit_SetFontSize(hCtrl,
Add)

Sets the font size for the selected text in the rich edit control.

Parameters

AddChange in point size of the selected text.  The change is applied to each part of the selection.  So, if some of the text is 10pt and some 20pt, after a call with wParam set to 1, the font sizes become 11pt and 22pt, respectively.

Returns

True if no error occurred, false otherwise.

SetModify

RichEdit_SetModify(hEdit,  
State = true)

Sets or clears the modification flag for an edit control.  The modification flag indicates whether the text within the edit control has been modified.

Related

GetModify, Save

SetOptions

RichEdit_SetOptions(hCtrl,
Operation,
Options)

Sets the options for a rich edit control.

Parameters

OperationSpecifies the operation.
OptionsWhite separted list of option values.

Operation

SETSets the options to those specified by Options.
ORCombines the specified options with the current options.
ANDRetains only those current options that are also specified by Options.
XORLogically exclusive OR the current options with those specified by Options.

Options

AUTOWORDSELECTIONAutomatic selection of word on double-click.
AUTOVSCROLLSame as AUTOVSCROLL style.
AUTOHSCROLLSame as AUTOHSCROLL style.
NOHIDESELSame as NOHIDESEL style.
READONLYSame as READONLY style.
WANTRETURNSame as WANTRETURN style.
SELECTIONBARSame as SELECTIONBAR style.  Returns: Returns the current options of the edit control.

PageRotate

RichEdit_PageRotate(hCtrl,  
R = "")

Rotate page.

Parameters

RCan be one of the following: 0,90,180,270.

Returns

If R is omitted, functin returns current rotation.

SetParaFormat

RichEdit_SetParaFormat(hCtrl,  
o1 = "",
o2 = "",
o3 = "",
o4 = "",
o5 = "",
o6 = "")

Sets the paragraph formatting for the current selection in a rich edit control.

Parameters

o1..o6Named arguments: Num, Align, Line, Ident, Space, Tabs.  Each named arugment has its own set of parameters (delimited by comma).  The syntax is “Name=a1,a2,a3,a4”.

Num :

TypeEMPTY, BULLET, DECIMAL, LOWER, UPPER, ROMAN_LOWER, ROMAN_UPPER, SEQUENCE (Uses a sequence of characters beginning with the character specified by the start argument).
StartStarting number or starting value used for numbered paragraphs.
StyleOne of the following :
  • RP - Follows the number with a right parenthesis.
  • P - Encloses the number in parentheses.
  • D - Follows the number with a dot.
  • N - Displays only the number.
  • CONT - Continues a numbered list without applying the next number or bullet.
  • NEW - Starts a new number with value of Start parameter.
OffsetMinimum space between a paragraph number and the paragraph text, in twips.

Align :

TypeCENTER, LEFT, RIGHT, JUSTIFY.

Line :

RuleOne of the following :
  • SINGLE - Single spacing.
  • 1ANDHALF - One-and-a-half spacing.
  • DOUBLE - Double spacing.
  • S1 - The Spacing specifies the spacing from one line to the next, in twips.  However, if Spacing specifies a value that is less than single spacing, the control displays single-spaced text.
  • S2 - The Spacing specifies the spacing from one line to the next, in twips.  The control uses the exact spacing specified, even if Spacing specifies a value that is less than single spacing.
  • S3 - The value of Spacing/20 is the spacing, in lines, from one line to the next.  Thus, setting Spacing to 20 produces single-spaced text, 40 is double spaced, 60 is triple spaced, and so on.
SpacingSpacing between lines.  This value is valid only for S1-S3 Rules.

Ident :

FirstIndentation of the paragraph’s first line, relative to the paragraph’s current indentation, in twips.  The indentation of subsequent lines depends on the Offset member.  To see all this in effect you must enable word wrap mode.  If starts with “.”, it represents absolute indentation from the left margin.
OffsetIndentation of the second and subsequent lines, relative to the indentation of the first line, in twips.  The first line is indented if this member is negative or outdented if this member is positive.
RightIndentation of the right side of the paragraph, relative to the right margin, in twips.

Space :

BeforeSize of the spacing above the paragraph, in twips.
AfterSpecifies the size of the spacing below the paragraph, in twips.

Tabs :

ListSpace separated list of absolute tab stop positions in twips.

Returns

True if succeessiful, false otherwise.

Remarks

Control uses carriage return character (`r) for paragraph markers by default.

SetEditStyle

RichEdit_SetEditStyle(hCtrl,
Style)

Sets the current edit style flags.

Parameters

StyleOne of the styles bellow.  Prepend “-” to turn the style off.

Styles

EMULATESYSEDITWhen this bit is on, rich edit attempts to emulate the system edit control.
BEEPONMAXTEXTRich Edit will call the system beeper if the user attempts to enter more than the maximum characters.
EXTENDBACKCOLORExtends the background color all the way to the edges of the client rectangle.
USEAIMMUses the AIMM input method component that ships with Microsoft Internet Explorer 4.0 or later.
UPPERCASEConverts all input characters to uppercase.
LOWERCASEConverts all input characters to lowercase.
XLTCRCRLFTOCRTurns on translation of CRCRLFs to CRs.  When this bit is on and a file is read in, all instances of CRCRLF will be converted to hard CRs internally.  This will affect the text wrapping.  Note that if such a file is saved as plain text, the CRs will be replaced by CRLFs.  This is the .txt standard for plain text.
SCROLLONKILLFOCUSWhen KillFocus occurs, scroll to the beginning of the text.

Returns

State of the edit style flags after rich edit has attempted to implement your edit style changes (number).

SetSel

RichEdit_SetSel(hCtrl,  
CpMin = 0,
CpMax = 0)

Selects a range of characters or Component Object Model (COM) objects in a rich edit control.

Parameters

CpMinBeginning of range of characters to select.
CpMaxEnd of range of characters to select.

Remarks

If the cpMin and cpMax members are equal, or cpMax is omitted, the cursor will be moved to cpMin’s position.  The range includes everything if cpMin is 0 and cpMax is –1.

Returns

The selection that is actually set.

Related

HideSelection, SetText, GetSel, GetText, GetTextLength

Example

RichEdit_SetSel( hRichEdit, 4, 10 ) ; select range
RichEdit_SetSel( hRichEdit, 2 )     ; move cursor to right of 2nd character
RichEdit_SetSel( hRichEdit, 0, -1 ) ; select all

SetText

RichEdit_SetText(HCtrl,  
Txt = "",
Flag = 0,
Pos = "")

Set text from string or file in rich edit control using either rich text or plain text.

Parameters

TxtThe text string to set within control.  To set RTF mark-up the Txt must be prefixed with “{rtf”.
FlagSpace separated list of options.  See below list.
PosThis optional parameter allows you to specify a character position you want text inserted to, rather than replacing current selection.  To append to the end, use -1.  When using SELECTION flag, the position is relative to the current selection text and current selection is expanded to contain new text.  If used without SELECTION flag existing selection remains unafected.

Flags

DEFAULTDeletes the undo stack, discards rich-text formatting, & replaces all text.
KEEPUNDOKeeps the undo stack.
SELECTIONReplaces selection and keeps rich-text formatting.  If you don’t specify this style entire content of the control will be replaced with the new text.
FROMFILELoad a file into control.  If used, this option expects the txt parameter to be a filename.  If there is a problem loading the file, ErrorLevel will contain message.

Returns

If the operation is setting all of the text and succeeds, the return value is 1.  If the operation fails, the return value is zero.

Related

SetSel, GetText, GetSel, TextMode

Example

FileSelectFile, file,,, Select file, RTF(*.rtf; *.txt)
RichEdit_SetText(hRichEdit, file, "FROMFILE KEEPUNDO")

RichEdit_SetText(hRichEdit, "insert..", "SELECTION")

RichEdit_SetText(hRichEdit, "replace all..")

RichEdit_SetText(hRichEdit, "append to end of selection..", "SELECTION", -1 )

SetUndoLimit

RichEdit_SetUndoLimit(hCtrl,
nMax)

Set the maximum number of actions that can stored in the undo queue of the rich edit control.

Parameters

nMaxThe maximum number of actions that can be stored in the undo queue.

Returns

The return value is the new maximum number of undo actions for the rich edit control.

Remarks

By default, the maximum number of actions in the undo queue is 100.  If you increase this number, there must be enough available memory to accommodate the new number.  For better performance, set the limit to the smallest possible value needed.

Related

Undo, GetUndo, Redo, GetRedo

Example

MsgBox, % RichEdit_SetUndoLimit( hRichEdit, 5 )

ShowScrollBar

RichEdit_ShowScrollBar(hCtrl,  
Bar,  
State = true)

Shows or hides scroll bars for Edit control.

Parameters

BarIdentifies which scroll bar to display: horizontal or vertical.  This parameter must be “V”, “H”, or a combination of the two.
StateTrue or false.

Remarks

This method is only valid when the control is in-place active.  Calls made while the control is inactive may fail.

Related

ScrollPos

Example

RichEdit_ShowScrollBar( hRichEdit, "VH", false )
Sleep, 3000

RichEdit_ShowScrollBar( hRichEdit, "V", true )

TextMode

RichEdit_TextMode(HCtrl,  
TextMode = "")

Get or set the current text mode of a rich edit control.

Parameters

TextModeSpace separated list of options (see below).  If omitted, current text mode is returned.

Options

Specify one of the following values to set the text mode parameter.  If you don’t specify a text mode value, the text mode remains at its current setting.

PLAINTEXTIndicates plain-text mode, in which the control is similar to a standard edit control.
RICHTEXTIndicates rich-text mode (default text mode).

Specify one of the following values to set the undo level parameter.  If you don’t specify an undo level value, the undo level remains at its current setting.

SINGLELEVELUNDOThe control allows the user to undo only the last action in the undo queue.
MULTILEVELUNDOThe control supports multiple undo actions (default undo mode).  Use SetUndoLimit to set the maximum number of undo actions.

Specify one of the following values to set the code page parameter.  If you don’t specify an code page value, the code page remains at its current setting.

SINGLECODEPAGEThe control only allows the English keyboard and a keyboard corresponding to the default character set.  For example, you could have Greek and English.  Note that this prevents Unicode text from entering the control.  For example, use this value if a rich edit control must be restricted to ANSI text.
MULTICODEPAGEThe control allows multiple code pages and Unicode text into the control (default code page mode).

Returns

If TextMode is omitted, the return value is the current text mode settings.  When TextMode is given, function will return true or false.

Remarks

The control text will be deleted when calling this function.

In rich text mode, a rich edit control has standard rich edit functionality.  However, in plain text mode, the control is similar to a standard edit control :

  • The text in a plain text control can have only one format (such as Bold, 10pt Arial).
  • The user cannot paste rich text formats, such as Rich Text Format (RTF) or embedded objects into a plain text control.
  • Rich text mode controls always have a default end-of-document marker or carriage return, to format paragraphs.
  • Plain text controls, on the other hand, do not need the default, end-of-document marker, so it is omitted.

Related

SetUndoLimit

Example

MsgBox, % "mode= " RichEdit_TextMode(hRichEdit)

If RichEdit_TextMode( hRichEdit, "PLAINTEXT SINGLELEVELUNDO" )
      MsgBox, % "new mode= " RichEdit_TextMode(hRichEdit)
Else  MsgBox, % errorlevel

WordWrap

RichEdit_WordWrap(HCtrl,
Flag)

Set word wrap mode in rich edit control.

Parameters

FlagTrue or false.

Returns

The return value is zero if the operation fails, or nonzero if it succeeds.

Zoom

Richedit_Zoom(hCtrl,  
zoom = )

Sets the zoom ratio anywhere between 1/64 and 64.

Parameters

zoomInteger amount to increase or decrease zoom with + or - infront of it (see examples).

Returns

If the new zoom setting is accepted, the return value is true.  If the new zoom setting is not accepted, the return value is false.  If zoom param is omitted, current numerator/denominator ratio is returned.

Examples

Msgbox, % "zoom ratio: " RichEdit_Zoom( hRichEdit )

#MaxHotkeysPerInterval 200
#IfWinActive ahk_group RichEditGrp
^WheelUp::   RichEdit_Zoom( hRichEdit, +1 )
^WheelDown:: RichEdit_Zoom( hRichEdit, -1 )
#IfWinActive

Undo

RichEdit_Undo(hCtrl,  
Reset = false)

Send message to Edit control to undo the next action in the control’s undo queue & optionally empty the undo buffer by resetting the undo flag.

Parameters

ResetSet to true to clear the undo buffer rather than send undo command.

Returns

For a single-line edit control, the return value is always true.  For a multiline edit control, the return value is true if the undo operation is successful, or false if the undo operation fails, or your resetting the undo queue.

RichEdit_Add(HParent,  
X = "",
Y = "",
W = "",
H = "",
Style = "",
Text = "")
Create rich edit version 4.1 control.
RichEdit_AutoUrlDetect(HCtrl,  
Flag = "")
Enable, disable, or toggle automatic detection of URLs in the RichEdit control.
RichEdit_CanPaste(hEdit,  
ClipboardFormat = 0x1)
Determines whether an Edit control can paste a specified clipboard format.
RichEdit_CharFromPos(hEdit,
X,
Y)
Gets information about the character closest to a specified point in the client area of the Edit control.
RichEdit_Clear(hEdit)
Send to an Edit control or combo box to delete (clear) the current selection.
RichEdit_Convert(Input,  
Direction = )
Convert twips to pixels or vice-versa.
RichEdit_Copy(hEdit)
Copy selection of the Edit control.
RichEdit_Cut(hEdit)
Cut selection from the Edit control.
RichEdit_FindText(hEdit,  
Text,  
CpMin = 0,
CpMax = -1,
Flags = "UNICODE")
Find desired text in the Edit control.
RichEdit_FindWordBreak(hCtrl,  
CharIndex,  
Flag = "")
Finds the next word break in rich edit conttrol, before or after the specified character position or retrieves information about the character at that position.
RichEdit_FixKeys(hCtrl)
Fix Tab and Esc key handling in rich edit control.
RichEdit_GetLine(hEdit,  
LineNumber = -1)
Get the text of the desired line from an Edit control.
RichEdit_GetLineCount(hEdit)
Gets the number of lines in a multiline Edit control.
RichEdit_GetOptions(hCtrl)
Get the options for a rich edit control.
RichEdit_GetCharFormat( hCtrl,  
ByRef Face = "",
ByRef Style = "",
ByRef TextColor = "",
ByRef BackColor = "",
 Mode = "SELECTION")
Determines the character formatting in a rich edit control.
RichEdit_GetRedo( hCtrl,  
ByRef name = "-")
Determine whether there are any actions in the rich edit control redo queue, and optionally retrieve the type of the next redo action.
RichEdit_GetModify(hEdit)
Gets the state of the modification flag for the Edit control.
RichEdit_GetRect( hEdit,  
ByRef Left = "",
ByRef Top = "",
ByRef Right = "",
ByRef Bottom = "")
Gets the formatting rectangle of the Edit control.
RichEdit_GetSel( hCtrl,  
ByRef cpMin = "",
ByRef cpMax = "")
Retrieve the starting and ending character positions of the selection in a rich edit control.
RichEdit_GetText(HCtrl,  
CpMin = "-",
CpMax = "-",
CodePage = "")
Retrieves a specified range of characters from a rich edit control.
RichEdit_GetTextLength(hCtrl,  
Flags = 0,
CodePage = "")
Calculates text length in various ways for a rich edit control.
RichEdit_GetUndo( hCtrl,  
ByRef Name = "-")
Determine whether there are any actions in the Edit control undo queue, and optionally retrieve the type of the next undo action.
RichEdit_HideSelection(hCtrl,  
State = true)
Hides or shows the selection in a rich edit control.
RichEdit_LineFromChar(hCtrl,  
CharIndex = -1)
Determines which line contains the specified character in a rich edit control.
RichEdit_LineIndex(hEdit,  
LineNumber = -1)
Returns the character index of the first character of a specified line in an Edit control.
RichEdit_LineLength(hEdit,  
LineNumber = -1)
Returns the length of a line in an Edit control.
RichEdit_LineScroll(hEdit,  
XScroll = 0,
YScroll = 0)
Scrolls the text in the Edit control.
RichEdit_LimitText(hCtrl,  
txtSize = )
Sets an upper limit to the amount of text the user can type or paste into a rich edit control.
RichEdit_Paste(hEdit)
Paste clipboard into the Edit control.
RichEdit_PasteSpecial(HCtrl,
Format)
Pastes a specific clipboard format in a rich edit control.
RichEdit_PosFromChar( hEdit,
 CharIndex,
ByRef X,
ByRef Y)
Gets the client area coordinates of a specified character in an Edit control.
RichEdit_Redo(hEdit)
Do redo operation.
RichEdit_ReplaceSel(hEdit,  
Text = "")
Replace selection with desired text in the Edit control.
RichEdit_Save(hCtrl,  
FileName = "")
Save the content of the rich edit control using RT format.
RichEdit_ScrollCaret(hEdit)
Scroll content of Edit control until caret is visible.
RichEdit_ScrollPos(HCtrl,  
PosString = "")
Obtain the current scroll position, or tell the rich edit control to scroll to a particular point.
RichEdit_SelectionType(hCtrl)
Determines the selection type for a rich edit control.
RichEdit_SetBgColor(hCtrl,
Color)
Sets the background color for a rich edit control.
RichEdit_SetCharFormat(HCtrl,  
Face = "",
Style = "",
TextColor = "",
BackColor = "",
Mode = "SELECTION")
Set character formatting in a rich edit control.
RichEdit_SetEvents(hCtrl,  
Handler = "",
Events = "selchange")
Set notification events.
RichEdit_SetFontSize(hCtrl,
Add)
Sets the font size for the selected text in the rich edit control.
RichEdit_SetModify(hEdit,  
State = true)
Sets or clears the modification flag for an edit control.
RichEdit_SetOptions(hCtrl,
Operation,
Options)
Sets the options for a rich edit control.
RichEdit_PageRotate(hCtrl,  
R = "")
Rotate page.
RichEdit_SetParaFormat(hCtrl,  
o1 = "",
o2 = "",
o3 = "",
o4 = "",
o5 = "",
o6 = "")
Sets the paragraph formatting for the current selection in a rich edit control.
RichEdit_SetEditStyle(hCtrl,
Style)
Sets the current edit style flags.
RichEdit_SetSel(hCtrl,  
CpMin = 0,
CpMax = 0)
Selects a range of characters or Component Object Model (COM) objects in a rich edit control.
RichEdit_SetText(HCtrl,  
Txt = "",
Flag = 0,
Pos = "")
Set text from string or file in rich edit control using either rich text or plain text.
RichEdit_SetUndoLimit(hCtrl,
nMax)
Set the maximum number of actions that can stored in the undo queue of the rich edit control.
RichEdit_ShowScrollBar(hCtrl,  
Bar,  
State = true)
Shows or hides scroll bars for Edit control.
RichEdit_TextMode(HCtrl,  
TextMode = "")
Get or set the current text mode of a rich edit control.
RichEdit_WordWrap(HCtrl,
Flag)
Set word wrap mode in rich edit control.
Richedit_Zoom(hCtrl,  
zoom = )
Sets the zoom ratio anywhere between 1/64 and 64.
RichEdit_Undo(hCtrl,  
Reset = false)
Send message to Edit control to undo the next action in the control’s undo queue & optionally empty the undo buffer by resetting the undo flag.
Close