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.
RichEdit | This module allows you to create and programmatically set text properties in rich edit control. |
Add | Create rich edit version 4.1 control. |
AutoUrlDetect | Enable, disable, or toggle automatic detection of URLs in the RichEdit control. |
CanPaste | Determines whether an Edit control can paste a specified clipboard format. |
CharFromPos | Gets information about the character closest to a specified point in the client area of the Edit control. |
Clear | Send to an Edit control or combo box to delete (clear) the current selection. |
Convert | Convert twips to pixels or vice-versa. |
Copy | Copy selection of the Edit control. |
Cut | Cut selection from the Edit control. |
FindText | Find desired text in the Edit control. |
FindWordBreak | 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. |
FixKeys | Fix Tab and Esc key handling in rich edit control. |
GetLine | Get the text of the desired line from an Edit control. |
GetLineCount | Gets the number of lines in a multiline Edit control. |
GetOptions | Get the options for a rich edit control. |
GetCharFormat | Determines the character formatting in a rich edit control. |
GetRedo | Determine whether there are any actions in the rich edit control redo queue, and optionally retrieve the type of the next redo action. |
GetModify | Gets the state of the modification flag for the Edit control. |
GetParaFormat | Retrieves the paragraph formatting of the current selection in a rich edit control. |
GetRect | Gets the formatting rectangle of the Edit control. |
GetSel | Retrieve the starting and ending character positions of the selection in a rich edit control. |
GetText | Retrieves a specified range of characters from a rich edit control. |
GetTextLength | Calculates text length in various ways for a rich edit control. |
GetUndo | Determine whether there are any actions in the Edit control undo queue, and optionally retrieve the type of the next undo action. |
HideSelection | Hides or shows the selection in a rich edit control. |
LineFromChar | Determines which line contains the specified character in a rich edit control. |
LineIndex | Returns the character index of the first character of a specified line in an Edit control. |
LineLength | Returns the length of a line in an Edit control. |
LineScroll | Scrolls the text in the Edit control. |
LimitText | Sets an upper limit to the amount of text the user can type or paste into a rich edit control. |
Paste | Paste clipboard into the Edit control. |
PasteSpecial | Pastes a specific clipboard format in a rich edit control. |
PosFromChar | Gets the client area coordinates of a specified character in an Edit control. |
Redo | Do redo operation. |
ReplaceSel | Replace selection with desired text in the Edit control. |
Save | Save the content of the rich edit control using RT format. |
ScrollCaret | Scroll content of Edit control until caret is visible. |
ScrollPos | Obtain the current scroll position, or tell the rich edit control to scroll to a particular point. |
SelectionType | Determines the selection type for a rich edit control. |
SetBgColor | Sets the background color for a rich edit control. |
SetCharFormat | Set character formatting in a rich edit control. |
SetEvents | Set notification events. |
SetFontSize | Sets the font size for the selected text in the rich edit control. |
SetModify | Sets or clears the modification flag for an edit control. |
SetOptions | Sets the options for a rich edit control. |
PageRotate | Rotate page. |
SetParaFormat | Sets the paragraph formatting for the current selection in a rich edit control. |
SetEditStyle | Sets the current edit style flags. |
SetSel | Selects a range of characters or Component Object Model (COM) objects in a rich edit control. |
SetText | Set text from string or file in rich edit control using either rich text or plain text. |
SetUndoLimit | Set the maximum number of actions that can stored in the undo queue of the rich edit control. |
ShowScrollBar | Shows or hides scroll bars for Edit control. |
TextMode | Get or set the current text mode of a rich edit control. |
WordWrap | Set word wrap mode in rich edit control. |
Zoom | Sets the zoom ratio anywhere between 1/64 and 64. |
Undo | 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. |
About |
RichEdit_Add( HParent, X = "", Y = "", W = "", H = "", Style = "", Text = "" )
Create rich edit version 4.1 control. (requires at least Windows XP SP1)
HParent | Handle of the parent of the control. |
X..H | Position. |
Style | White 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. |
Text | Control text. Styles: |
DISABLENOSCROLL | Disables scroll bars instead of hiding them when they are not needed. |
BORDER | Displays the control with a sunken border style so that the rich edit control appears recessed into its parent window. |
HIDDEN | Don’t show the control. |
VSCROLL | Enble vertical scroll bar. |
HSCROLL | Enable horizontal scroll bar. If this style is present control starts with wrap mode deactivated. Otherwise, wrap mode is active. |
SCROLL | Enable both scroll bars. |
AUTOHSCROLL | Automatically 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. |
AUTOVSCROLL | Automatically scrolls text up one page when the user presses the ENTER key on the last line. |
CENTER | Centers text in a single-line or multiline edit control. |
LEFT | Left aligns text. |
MULTILINE | Designates a multiline edit control. The default is single-line edit control. |
NOHIDESEL | Negates 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. |
NUMBER | Allows only digits to be entered into the edit control. |
PASSWORD | Displays an asterisk (*) for each character typed into the edit control. This style is valid only for single-line edit controls. |
READONLY | Prevents the user from typing or editing text in the edit control. |
RIGHT | Right aligns text in a single-line or multiline edit control. |
SELECTIONBAR | When 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. |
WANTRETURN | Specifies 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. |
Control’s handle or 0. Error message on problem.
Gui, +LastFound hwnd := WinExist() hRichEdit := RichEdit_Add(hwnd, 5, 5, 200, 300) Gui, Show, w210 h310
RichEdit_AutoUrlDetect( HCtrl, Flag = "" )
Enable, disable, or toggle automatic detection of URLs in the RichEdit control.
Flag | Specify 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. |
If auto-URL detection is active, the return value is 1. If auto-URL detection is inactive, the return value is 0.
MsgBox, % RichEdit_AutoUrlDetect( hRichEdit, true ) MsgBox, % RichEdit_AutoUrlDetect( hRichEdit, "^" ) MsgBox, % "Current state: " RichEdit_AutoUrlDetect( hRichEdit )
RichEdit_CanPaste( hEdit, ClipboardFormat = 0x1 )
Determines whether an Edit control can paste a specified clipboard format.
ClipboardFormat | Specifies the Clipboard Formats to try. To try any format currently on the clipboard, set this parameter to zero. The default is 0x1 (CF_TEXT). |
True if the clipboard format can be pasted otherwise false.
For additional information on clipboard formats, see the following: http://msdn.microsoft.com
If RichEdit_CanPaste( hRichEdit, 0 ) RichEdit_Paste( hRichEdit ) Else MsgBox, Cannot paste your clipboard into control..
RichEdit_CharFromPos( hEdit, X, Y )
Gets information about the character closest to a specified point in the client area of the Edit control.
X, Y | The coordinates of a point in the Edit control’s client area relative to the upper-left corner of the client area. |
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.
RichEdit_Convert( Input, Direction = )
Convert twips to pixels or vice-versa.
Input | Twips (Input>0) or pixels (Input<0). |
Direction | 0 (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. |
RichEdit_FindText( hEdit, Text, CpMin = 0, CpMax = -1, Flags = "UNICODE" )
Find desired text in the Edit control.
Text | Text to be searched for. |
CpMin | Start searching at this character position. By default 0. |
CpMax | End searching at this character position. When searching forward, a value of 1 extends the search range to the end of the text. |
Flags | Space separated combination of search flags. See below. |
WHOLEWORD | If 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. |
MATCHCASE | If set, the search operation is case-sensitive. If not set, the search operation is case-insensitive. |
DOWN | Rich 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. |
UNICODE | Transforms 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.
^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
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.
CharIndex | Zero-based character starting position. |
Flag | One of the flags list below. |
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, or false otherwise. |
LEFT | Finds the nearest character before the specified position that begins a word. |
LEFTBREAK | Finds the next word end before the specified position. This value is the same as PREVBREAK. |
MOVEWORDLEFT | Finds the next character that begins a word before the specified position. This value is used during CTRL+LEFT ARROW key processing. |
MOVEWORDRIGHT | Finds the next character that begins a word after the specified position. This value is used during CTRL+right key processing. |
RIGHT | Finds the next character that begins a word after the specified position. |
RIGHTBREAK | Finds the next end-of-word delimiter after the specified position. This value is the same as NEXTBREAK. |
The message returns a value based on the wParam parameter.
RichEdit_FixKeys( hCtrl )
Fix Tab and Esc key handling in rich edit control.
True or false.
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.
RichEdit_GetLine( hEdit, LineNumber = -1 )
Get the text of the desired line from an Edit control.
LineNumber | Zero-based index of the line. -1 means current line. |
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.
RichEdit_GetLineCount( hEdit )
Gets the number of lines in a multiline Edit control.
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.
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.
RichEdit_GetOptions( hCtrl )
Get the options for a rich edit control.
See SetOptions for details.
RichEdit_GetCharFormat( hCtrl, ByRef Face = "", ByRef Style = "", ByRef TextColor = "", ByRef BackColor = "", Mode = "SELECTION" )
Determines the character formatting in a rich edit control.
Face | Optional byref parameter will contain the name of the font. |
Style | Optional byref parameter will contain a space separated list of styles. See SetCharFormat for list of styles. |
TextColor | Text forground color. If starts with “-” the color is AUTOCOLOR. |
BackColor | Text background color. If starts with “-” the color is AUTOCOLOR. |
Mode | If 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. |
Function will get the attributes of the first character.
RichEdit_GetCharFormat(hRichEdit, face, style, color) MsgBox, Face = %Face% `nstyle = %style% `ncolor = %color%
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.
name | This optional parameter is the name of the variable in which to store the type of redo action, if any. |
UNKNOWN | The type of undo action is unknown. |
TYPING | Typing operation. |
DELETE | Delete operation. |
DRAGDROP | Drag-and-drop operation. |
CUT | Cut operation. |
PASTE | Paste operation. |
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.
Redo, GetUndo, Undo, SetUndoLimit
If RichEdit_GetRedo( hRichEdit, name ) MsgBox, The next redo is a %name% type Else MsgBox, Nothing left to redo.
RichEdit_GetSel( hCtrl, ByRef cpMin = "", ByRef cpMax = "" )
Retrieve the starting and ending character positions of the selection in a rich edit control.
cpMin | The optional name of the variable in which to store the character position index immediately preceding the first character in the range. |
cpMin | The optional name of the variable in which to store the character position index immediately following the last character in the range. |
Returns cpMin. If there is no selection this is cursor position.
GetText, GetTextLength, SetSel, SetText, HideSelection, LineFromChar
RichEdit_GetText( HCtrl, CpMin = "-", CpMax = "-", CodePage = "" )
Retrieves a specified range of characters from a rich edit control.
CpMin | Beginning of range of characters to retrieve. |
CpMax | End of range of characters to retrieve. |
CodePage | If UNICODE or U, this optional parameter will use unicode code page in the translation. Otherwise it will default to using ansi. (*** needs rework ***) |
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 the retrieved text.
GetSel, GetLine, GetTextLength, SetText, SetSel, FindText
MsgBox, % RichEdit_GetText( hRichEdit ) ; get current selection MsgBox, % RichEdit_GetText( hRichEdit, 0, -1 ) ; get all MsgBox, % RichEdit_GetText( hRichEdit, 4, 10 ) ; get range
RichEdit_GetTextLength( hCtrl, Flags = 0, CodePage = "" )
Calculates text length in various ways for a rich edit control.
flag | Space separated list of one or more options. See below list. |
codepage | If UNICODE or U, this optional parameter will use unicode code page in the translation. Otherwise it will default to using ansi. |
DEFAULT | Returns the number of characters. This is the default. |
USECRLF | Computes the answer by using CR/LFs at the end of paragraphs. |
PRECISE | Computes a precise answer. This approach could necessitate a conversion and thereby take longer. This flag cannot be used with the CLOSE flag. |
CLOSE | Computes 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. |
NUMCHARS | Returns the number of characters. This flag cannot be used with the NUMBYTES flag. |
NUMBYTES | Returns the number of bytes. This flag cannot be used with the NUMCHARS flag. |
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.
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.
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"
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.
Name | Optional byref parameter will contain the type of undo action, if any. |
UNKNOWN | The type of undo action is unknown. |
TYPING | Typing operation. |
DELETE | Delete operation. |
DRAGDROP | Drag-and-drop operation. |
CUT | Cut operation. |
PASTE | Paste operation. |
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.
Undo, SetUndoLimit, GetRedo, Redo
If RichEdit_GetRedo( hRichEdit, name ) MsgBox, The next redo is a %name% type Else MsgBox, Nothing left to redo.
RichEdit_HideSelection( hCtrl, State = true )
Hides or shows the selection in a rich edit control.
State | True or false. |
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.
RichEdit_LineIndex( hEdit, LineNumber = -1 )
Returns the character index of the first character of a specified line in an Edit control.
LineNumber | Line number for which to retreive character index. -1 (default) means current line. |
The character index of the line specified, or -1 if the specified line number is greater than the number of lines.
RichEdit_LineScroll( hEdit, XScroll = 0, YScroll = 0 )
Scrolls the text in the Edit control.
XScroll | The number of characters to scroll horizontally. Use a negative number to scroll to the left and a positive number to scroll to the right. |
YScroll | The 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. |
RichEdit_LimitText( hCtrl, txtSize = )
Sets an upper limit to the amount of text the user can type or paste into a rich edit control.
txtSize | Specifies 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. |
This function does not return a value.
Before LimitText is called, the default limit to the amount of text a user can enter is 32,767 characters.
RichEdit_Paste( hEdit )
Paste clipboard into the Edit control.
CanPaste, PasteSpecial, Cut, Copy, Clear
RichEdit_PasteSpecial( HCtrl, Format )
Pastes a specific clipboard format in a rich edit control.
Format | One of the clipboard formats. See http://msdn.microsoft.com |
RichEdit_PosFromChar( hEdit, CharIndex, ByRef X, ByRef Y )
Gets the client area coordinates of a specified character in an Edit control.
CharIndex | The zero-based index of the character. |
X, Y | These 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. |
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.
RichEdit_Save( hCtrl, FileName = "" )
Save the content of the rich edit control using RT format.
FileName | File name to save RTF file to. If omitted, function will return content. |
If !RichEdit_GetModify( hRichEdit ) { MsgBox, No changes detected return } RichEdit_Save( hRichEdit, file ) RichEdit_SetModify( hRichEdit, false ) MsgBox, File has been saved
RichEdit_ScrollPos( HCtrl, PosString = "" )
Obtain the current scroll position, or tell the rich edit control to scroll to a particular point.
PosString | String specifying the x/y point in the virtual text space of the document, expressed in pixels. (See example) |
If posString is omitted, the return value is the current scroll position.
ShowScrollBar, GetSel, LineFromChar, SetSel
Msgbox, % "scroll pos = " RichRichEdit_ScrollPos( hRichEdit ) RichRichEdit_ScrollPos( hRichEdit , "7/22" )
RichEdit_SelectionType( hCtrl )
Determines the selection type for a rich edit control.
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.
This message is useful during WM_SIZE processing for the parent of a bottomless rich edit control.
RichEdit_SetBgColor( hCtrl, Color )
Sets the background color for a rich edit control.
Color | Color in RGB format (0xRRGGBB) if > 0 or BGR format if < 0. |
Returns the previous background color in RGB format.
Dlg_Color( color, hRichEdit ) RichEdit_SetBgColor( hRichEdit, color ) RichEdit_SetBgColor( hRichEdit, 0xa9f874 )
RichEdit_SetCharFormat( HCtrl, Face = "", Style = "", TextColor = "", BackColor = "", Mode = "SELECTION" )
Set character formatting in a rich edit control.
Face | Font name. Optional. |
Style | Space separated list of styles. See below list. Optional. |
TextColor | Text foreground color. Optional. |
BackColor | Text backgrond color. Optional. |
Mode | Character 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. |
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. |
AUTOBACKCOLOR | The background color is the return value of GetSysColor(COLOR_WINDOW:=5). If this flag is set, BackColor member is ignored. |
AUTOCOLOR | The text color is the return value of GetSysColor(COLOR_WINDOWTEXT:=8). If this flag is set, the TextColor member is ignored. |
BOLD | Characters are bold. |
HIDDEN | Characters are not displayed. |
ITALIC | Characters are italic. |
LINK | A rich edit control sends LINK notification messages when it receives mouse messages while the mouse pointer is over text with the LINK effect. |
PROTECTED | Characters are protected; an attempt to modify them will cause an PROTECTED notification message. |
STRIKEOUT | Characters are struck out. |
SUBSCRIPT | Characters are subscript. The SUPERSCRIPT and SUBSCRIPT values are mutually exclusive. For both values, the control automatically calculates an offset and a smaller font size. |
SUPERSCRIPT | Characters are superscript. |
UNDERLINE | Characters are underlined. |
DEFAULT | Changes the formating for the default text in the control. This is also the style used if you don’t specify valid style. |
ALL | Applies the formatting to all text in the control. |
SELECTION | Applies 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. |
WORD | Applies 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. |
True or false.
This function will fire up SELCHANGE message even if selection isn’t changed.
RichEdit_SetEvents( hCtrl, Handler = "", Events = "selchange" )
Set notification events.
Handler | Function that handles events. If empty, any existing handler will be removed. |
Events | White space separated list of events to monitor. |
Result := Handler(hCtrl, Event, p1, p2, p3 )
hCtrl | Handle of richedit control sending the event. |
Event | Specifies event that occurred. Event must be registered to be able to monitor it. |
Col,Row | Cell coordinates. |
Data | Numeric data of the cell. Pointer to string for textual cells and DWORD value for numeric. |
Result | Return 1 to prevent action. |
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.
DROPFILES: Notifies that the user is attempting to drop files into the 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)
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.
SELCHANGE: The current selection has changed.
LINK: The hyperlink has been clicked.
The previous event mask (number).
RichEdit_SetFontSize( hCtrl, Add )
Sets the font size for the selected text in the rich edit control.
Add | Change 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. |
True if no error occurred, false otherwise.
RichEdit_SetOptions( hCtrl, Operation, Options )
Sets the options for a rich edit control.
Operation | Specifies the operation. |
Options | White separted list of option values. |
SET | Sets the options to those specified by Options. |
OR | Combines the specified options with the current options. |
AND | Retains only those current options that are also specified by Options. |
XOR | Logically exclusive OR the current options with those specified by Options. |
AUTOWORDSELECTION | Automatic selection of word on double-click. |
AUTOVSCROLL | Same as AUTOVSCROLL style. |
AUTOHSCROLL | Same as AUTOHSCROLL style. |
NOHIDESEL | Same as NOHIDESEL style. |
READONLY | Same as READONLY style. |
WANTRETURN | Same as WANTRETURN style. |
SELECTIONBAR | Same as SELECTIONBAR style. Returns: Returns the current options of the edit control. |
RichEdit_SetParaFormat( hCtrl, o1 = "", o2 = "", o3 = "", o4 = "", o5 = "", o6 = "" )
Sets the paragraph formatting for the current selection in a rich edit control.
o1..o6 | Named 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 :
Type | EMPTY, BULLET, DECIMAL, LOWER, UPPER, ROMAN_LOWER, ROMAN_UPPER, SEQUENCE (Uses a sequence of characters beginning with the character specified by the start argument). |
Start | Starting number or starting value used for numbered paragraphs. |
Style | One of the following : |
Offset | Minimum space between a paragraph number and the paragraph text, in twips. |
Align :
Type | CENTER, LEFT, RIGHT, JUSTIFY. |
Line :
Rule | One of the following : |
Spacing | Spacing between lines. This value is valid only for S1-S3 Rules. |
Ident :
First | Indentation 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. |
Offset | Indentation 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. |
Right | Indentation of the right side of the paragraph, relative to the right margin, in twips. |
Space :
Before | Size of the spacing above the paragraph, in twips. |
After | Specifies the size of the spacing below the paragraph, in twips. |
Tabs :
List | Space separated list of absolute tab stop positions in twips. |
True if succeessiful, false otherwise.
Control uses carriage return character (`r) for paragraph markers by default.
RichEdit_SetEditStyle( hCtrl, Style )
Sets the current edit style flags.
Style | One of the styles bellow. Prepend “-” to turn the style off. |
EMULATESYSEDIT | When this bit is on, rich edit attempts to emulate the system edit control. |
BEEPONMAXTEXT | Rich Edit will call the system beeper if the user attempts to enter more than the maximum characters. |
EXTENDBACKCOLOR | Extends the background color all the way to the edges of the client rectangle. |
USEAIMM | Uses the AIMM input method component that ships with Microsoft Internet Explorer 4.0 or later. |
UPPERCASE | Converts all input characters to uppercase. |
LOWERCASE | Converts all input characters to lowercase. |
XLTCRCRLFTOCR | Turns 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. |
SCROLLONKILLFOCUS | When KillFocus occurs, scroll to the beginning of the text. |
State of the edit style flags after rich edit has attempted to implement your edit style changes (number).
RichEdit_SetSel( hCtrl, CpMin = 0, CpMax = 0 )
Selects a range of characters or Component Object Model (COM) objects in a rich edit control.
CpMin | Beginning of range of characters to select. |
CpMax | End of range of characters to select. |
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.
The selection that is actually set.
HideSelection, SetText, GetSel, GetText, GetTextLength
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
RichEdit_SetText( HCtrl, Txt = "", Flag = 0, Pos = "" )
Set text from string or file in rich edit control using either rich text or plain text.
Txt | The text string to set within control. To set RTF mark-up the Txt must be prefixed with “{rtf”. |
Flag | Space separated list of options. See below list. |
Pos | This 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. |
DEFAULT | Deletes the undo stack, discards rich-text formatting, & replaces all text. |
KEEPUNDO | Keeps the undo stack. |
SELECTION | Replaces 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. |
FROMFILE | Load 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. |
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.
SetSel, GetText, GetSel, TextMode
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 )
RichEdit_SetUndoLimit( hCtrl, nMax )
Set the maximum number of actions that can stored in the undo queue of the rich edit control.
nMax | The maximum number of actions that can be stored in the undo queue. |
The return value is the new maximum number of undo actions for the rich edit control.
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.
MsgBox, % RichEdit_SetUndoLimit( hRichEdit, 5 )
RichEdit_ShowScrollBar( hCtrl, Bar, State = true )
Shows or hides scroll bars for Edit control.
Bar | Identifies which scroll bar to display: horizontal or vertical. This parameter must be “V”, “H”, or a combination of the two. |
State | True or false. |
This method is only valid when the control is in-place active. Calls made while the control is inactive may fail.
RichEdit_ShowScrollBar( hRichEdit, "VH", false ) Sleep, 3000 RichEdit_ShowScrollBar( hRichEdit, "V", true )
RichEdit_TextMode( HCtrl, TextMode = "" )
Get or set the current text mode of a rich edit control.
TextMode | Space separated list of options (see below). If omitted, current text mode is returned. |
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.
PLAINTEXT | Indicates plain-text mode, in which the control is similar to a standard edit control. |
RICHTEXT | Indicates 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.
SINGLELEVELUNDO | The control allows the user to undo only the last action in the undo queue. |
MULTILEVELUNDO | The 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.
SINGLECODEPAGE | The 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. |
MULTICODEPAGE | The control allows multiple code pages and Unicode text into the control (default code page mode). |
If TextMode is omitted, the return value is the current text mode settings. When TextMode is given, function will return true or false.
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 :
MsgBox, % "mode= " RichEdit_TextMode(hRichEdit) If RichEdit_TextMode( hRichEdit, "PLAINTEXT SINGLELEVELUNDO" ) MsgBox, % "new mode= " RichEdit_TextMode(hRichEdit) Else MsgBox, % errorlevel
Richedit_Zoom( hCtrl, zoom = )
Sets the zoom ratio anywhere between 1/64 and 64.
zoom | Integer amount to increase or decrease zoom with + or - infront of it (see examples). |
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.
Msgbox, % "zoom ratio: " RichEdit_Zoom( hRichEdit ) #MaxHotkeysPerInterval 200 #IfWinActive ahk_group RichEditGrp ^WheelUp:: RichEdit_Zoom( hRichEdit, +1 ) ^WheelDown:: RichEdit_Zoom( hRichEdit, -1 ) #IfWinActive
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.
Reset | Set to true to clear the undo buffer rather than send undo command. |
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.
Create rich edit version 4.1 control.
RichEdit_Add( HParent, X = "", Y = "", W = "", H = "", Style = "", Text = "" )
Enable, disable, or toggle automatic detection of URLs in the RichEdit control.
RichEdit_AutoUrlDetect( HCtrl, Flag = "" )
Determines whether an Edit control can paste a specified clipboard format.
RichEdit_CanPaste( hEdit, ClipboardFormat = 0x1 )
Gets information about the character closest to a specified point in the client area of the Edit control.
RichEdit_CharFromPos( hEdit, X, Y )
Send to an Edit control or combo box to delete (clear) the current selection.
RichEdit_Clear( hEdit )
Convert twips to pixels or vice-versa.
RichEdit_Convert( Input, Direction = )
Copy selection of the Edit control.
RichEdit_Copy( hEdit )
Cut selection from the Edit control.
RichEdit_Cut( hEdit )
Find desired text in the Edit control.
RichEdit_FindText( hEdit, Text, CpMin = 0, CpMax = -1, Flags = "UNICODE" )
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_FindWordBreak( hCtrl, CharIndex, Flag = "" )
Fix Tab and Esc key handling in rich edit control.
RichEdit_FixKeys( hCtrl )
Get the text of the desired line from an Edit control.
RichEdit_GetLine( hEdit, LineNumber = -1 )
Gets the number of lines in a multiline Edit control.
RichEdit_GetLineCount( hEdit )
Get the options for a rich edit control.
RichEdit_GetOptions( hCtrl )
Determines the character formatting in a rich edit control.
RichEdit_GetCharFormat( hCtrl, ByRef Face = "", ByRef Style = "", ByRef TextColor = "", ByRef BackColor = "", Mode = "SELECTION" )
Determine whether there are any actions in the rich edit control redo queue, and optionally retrieve the type of the next redo action.
RichEdit_GetRedo( hCtrl, ByRef name = "-" )
Gets the state of the modification flag for the Edit control.
RichEdit_GetModify( hEdit )
Gets the formatting rectangle of the Edit control.
RichEdit_GetRect( hEdit, ByRef Left = "", ByRef Top = "", ByRef Right = "", ByRef Bottom = "" )
Retrieve the starting and ending character positions of the selection in a rich edit control.
RichEdit_GetSel( hCtrl, ByRef cpMin = "", ByRef cpMax = "" )
Retrieves a specified range of characters from a rich edit control.
RichEdit_GetText( HCtrl, CpMin = "-", CpMax = "-", CodePage = "" )
Calculates text length in various ways for a rich edit control.
RichEdit_GetTextLength( hCtrl, Flags = 0, CodePage = "" )
Determine whether there are any actions in the Edit control undo queue, and optionally retrieve the type of the next undo action.
RichEdit_GetUndo( hCtrl, ByRef Name = "-" )
Hides or shows the selection in a rich edit control.
RichEdit_HideSelection( hCtrl, State = true )
Determines which line contains the specified character in a rich edit control.
RichEdit_LineFromChar( hCtrl, CharIndex = -1 )
Returns the character index of the first character of a specified line in an Edit control.
RichEdit_LineIndex( hEdit, LineNumber = -1 )
Returns the length of a line in an Edit control.
RichEdit_LineLength( hEdit, LineNumber = -1 )
Scrolls the text in the Edit control.
RichEdit_LineScroll( hEdit, XScroll = 0, YScroll = 0 )
Sets an upper limit to the amount of text the user can type or paste into a rich edit control.
RichEdit_LimitText( hCtrl, txtSize = )
Paste clipboard into the Edit control.
RichEdit_Paste( hEdit )
Pastes a specific clipboard format in a rich edit control.
RichEdit_PasteSpecial( HCtrl, Format )
Gets the client area coordinates of a specified character in an Edit control.
RichEdit_PosFromChar( hEdit, CharIndex, ByRef X, ByRef Y )
Do redo operation.
RichEdit_Redo( hEdit )
Replace selection with desired text in the Edit control.
RichEdit_ReplaceSel( hEdit, Text = "" )
Save the content of the rich edit control using RT format.
RichEdit_Save( hCtrl, FileName = "" )
Scroll content of Edit control until caret is visible.
RichEdit_ScrollCaret( hEdit )
Obtain the current scroll position, or tell the rich edit control to scroll to a particular point.
RichEdit_ScrollPos( HCtrl, PosString = "" )
Determines the selection type for a rich edit control.
RichEdit_SelectionType( hCtrl )
Sets the background color for a rich edit control.
RichEdit_SetBgColor( hCtrl, Color )
Set character formatting in a rich edit control.
RichEdit_SetCharFormat( HCtrl, Face = "", Style = "", TextColor = "", BackColor = "", Mode = "SELECTION" )
Set notification events.
RichEdit_SetEvents( hCtrl, Handler = "", Events = "selchange" )
Sets the font size for the selected text in the rich edit control.
RichEdit_SetFontSize( hCtrl, Add )
Sets or clears the modification flag for an edit control.
RichEdit_SetModify( hEdit, State = true )
Sets the options for a rich edit control.
RichEdit_SetOptions( hCtrl, Operation, Options )
Rotate page.
RichEdit_PageRotate( hCtrl, R = "" )
Sets the paragraph formatting for the current selection in a rich edit control.
RichEdit_SetParaFormat( hCtrl, o1 = "", o2 = "", o3 = "", o4 = "", o5 = "", o6 = "" )
Sets the current edit style flags.
RichEdit_SetEditStyle( hCtrl, Style )
Selects a range of characters or Component Object Model (COM) objects in a rich edit control.
RichEdit_SetSel( hCtrl, CpMin = 0, CpMax = 0 )
Set text from string or file in rich edit control using either rich text or plain text.
RichEdit_SetText( HCtrl, Txt = "", Flag = 0, Pos = "" )
Set the maximum number of actions that can stored in the undo queue of the rich edit control.
RichEdit_SetUndoLimit( hCtrl, nMax )
Shows or hides scroll bars for Edit control.
RichEdit_ShowScrollBar( hCtrl, Bar, State = true )
Get or set the current text mode of a rich edit control.
RichEdit_TextMode( HCtrl, TextMode = "" )
Set word wrap mode in rich edit control.
RichEdit_WordWrap( HCtrl, Flag )
Sets the zoom ratio anywhere between 1/64 and 64.
Richedit_Zoom( hCtrl, zoom = )
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.
RichEdit_Undo( hCtrl, Reset = false )