Date: 02-16-2022
Return to Index
created by gbSnippets
'This page provides a side-by-side comparison of common Edit Controls and Rich Edit control messages,
'descriptions of commonly used messages, and the wParam/lParam requirements for each message.
'All of these messages may be sent to the RichEdit control. However, those in the right column
'may be sent to the RichEdit control only.
'RichEdit vs TextBox: Basic Messages - Overlapping Functions --------------------------------------
' Edit or Rich Edit wparam/lparam RichEdit ONLY wparam/lparam
'--------------------------------------------------------------------------------------------------------------------
'Text Content WM_GetText (64K) MaxChar#, ptr-buffer EM_GetTextEX ptr-GETTEXTEX, p-Buffer(Z)
' WM_SetText 0, ptr-buffer EM_SetTextEx ptr-SETTEXTEX, p-Buffer(Z)
' EM_ReplaceSel T/F, ptr-buffer
' EM_GetLine line #, ptr-buffer(Z)
' EM_GetSelText 0, ptr-Buffer(Z)
' EM_GetTextRange 0, ptr-TEXTRANGE (start/end pos)
' EM_GetLimitText 0,0
' EM_SetLimitText # chars, 0 EM_EXLimitText 0, # char's
'-----------------------------------------------------------------------------------------------
'Text Length WM_GetTextLength 0,0 EM_GetTextLengthEX ptr-GETTEXTLENGTHEX,0
'------------------------------------------------------------------------------------------------
'Char Positions EM_GetSel (64K) ptr-Start,ptr-End EM_EXGetSel 0, ptr-CHARRANGE (start/end pos)
' EM_SetSel #start, #end EM_EXSetSel 0, ptr-CHARRANGE (start/end pos)
'-----------------------------------------------------------------------------------------------
'Lines (#s) EM_LineLength char #,0
' EM_LineIndex line #,0
' EM_LineFromChar char #,0 EM_EXLineFromChar 0, char # (zero-based pos)
' EM_GetLineCount 0,0
' EM_GetFirstVisibleLine 0,0
'----------------------------------------------------------------------------------------------
'Special Message Settings
'EM_GetLine 0, p-Buff top-most line
'EM_SetSel 0,-1 all selected
'EM_SetSel -1,0 none selected
'EM_LineFromChar -1,0 current line / line at beginning of selection
'EM_EXLineFromChar 0,-1 current line
'EM_SetLimitText 0,0 sets RichEdit to 64K
'EM_EXSetSel 0, p-CHARRANGE cpMin=cpMax then no selection 0,-1 then all text selected
'Structures -------------------------------------------------------------
'TEXTRANGE
' chrg CHARRANGE
' lpstrText pointer to RichEditBuffer
'CHARRANGE
' .cpMin Long char position immediately preceding the 1st char in the range
' .cpMax Long char position immediately following the last char in the range
'GETTEXTEX
' cb DWord count of bytes in retrieved string
' flags DWord gt_default, gt_selection, gt_usecrlf
' codepage UINT default codepage 1200
' lpDefaultChar LPCSTR only used if codepage <> 1200
' lpUsedDefChar LPBOOL only used If codepage <> 1200
'SETTEXTEX
' cb DWord count of bytes in retrieved string
' flags DWord gt_default, gt_selection, gt_usecrlf
' codepage UINT default codepage 1200
' lpDefaultChar LPCSTR only used if codepage <> 1200
' lpUsedDefChar LPBOOL only used If codepage <> 1200
'CHARFORMAT
' cbSize Dword
' dwMask Dword
' dwEffects Dword
' yHeight Long
' yOffset Long
' crTextColor Dword
' bCharSet Byte
' bPitchAndFamily Byte
' szFaceName ASCIIZ * %LF_FACESIZE
' wFiller Word
'Commonly Used Messages -------------------------------------------------
'Of approximately 200 messages/notifications, only about 50 are used extensively by programmers.
'Functions are zero based (first line/char is zero, NOT one)
'$CRLF counts as 2 characters, and may be selected (multiline edit control and RichEdit control)
'Edit Control OR RichEdit Control -------------------------------------------
'EM_GETFIRSTVISIBLELINE gets line# of uppermost visible line
'EM_GETLINE get a line of text
'EM_GETLINECOUNT get number of lines of text
'EM_GETSEL gets starting/ending character positions of the selection
'EM_GETLIMITTEXT gets current text limit
'EM_LINEFROMCHAR get line# containing specified character
'EM_LINEINDEX get char# of 1st char in specified line
'EM_LINELENGTH get # of characters in a specified line
'EM_REPLACESEL replaces selected text
'EM_SETLIMITTEXT sets max # characters user can type/paste into control
'EM_SETREADONLY prevents user from entering text
'EM_SETSEL selects a range of characters
'EM_UNDO undoes last edit control operation in the control's undo queue
'WM_GETTEXT copy all text
'WM_SETTEXT set all text
'WM_GETTEXTLENGTH get length of all text
'WM_UNDO undoes the last operation. previously deleted text is restored or previously added text is deleted
'RichEdit Control ONLY --------------------------------------------------------------------------
'EM_AUTOURLDETECT enables/disables automatic detection of URLs
'EM_EXGETSEL sets upper limit to amount of text user can type in/paste
'EM_EXLIMITTEXT sets upper limit on amount of text in control
'EM_EXLINEFROMCHAR get line# containing specified character position
'EM_EXSETSEL selects range of characters
'EM_FINDTEXT find text
'EM_FINDTEXTEX find text (more info in data structure)
'EM_GETEVENTMASK retrieves event mask (maks specifies which notifications the control sends)
'EM_GETSCROLLPOS current scroll position (upper/left pixel)
'EM_GETSELTEXT gets currently selected text
'EM_GETTEXTEX get all text in any code base
'EM_GETTEXTLENGTHEX get length of all text (various calculations)
'EM_GETTEXTRANGE get characters from a specified range
'EM_REDO redo the next action in the control's redo queue
'EM_SETBKGNDCOLOR sets background color
'EM_SETCHARFORMAT sets character formatting (all or selected text)
'EM_SETEVENTMASK specifies which notification messages the control sends to its parent window
'EM_SETFONTSIZE set font size for selected text
'EM_SETSCROLLPOS sets scroll position (upper/left pixel)
'EM_SETTEXTEX WM_SETTEXT and EM_REPLACESEL
'EM_STREAMIN replaces the text with a stream of data from application defined EditStreamCallback callback function
'EM_STREAMOUT gets text by sending to application–defined EditStreamCallback callback function.
'WM_SETREDRAW allow/disallow changes from being redrawn
'EM_STREAMIN replaces the contents of a rich edit control with a stream of data provided by an application defined callback
'EM_STREAMOUT pass RichEdit content to an application defined callback
'Message Arguments (same list of messages/notifications as above) ------------------------------------------------------------
'Selections are returned as startPos/endPos, where endPos is first character not selected
'Special Message Settings
'EM_GetLine 0, p-Buff top-most line
'EM_SetSel 0, -1 all selected
'EM_SetSel -1, 0 none selected
'EM_LineFromChar -1,0 current line / line at beginning of selection
'EM_EXLineFromChar 0,-1 current line
'Message wParam lParam Return + Notes
------------------- -------------- ----------------- --------------------------------------------------------
'EM_GetFirstVisibleLine n/u n/u first visible line
'EM_GetLine line# ptr to buffer number of char's returned
'EM_GetLineCount n/u 0 n/u 0 # of lines (not just visible lines)
'EM_GetSel ptr to StartPos ptr to EndPos+1 ?? Note: if no selection, points to caret, 64K limit
'EM_GetLimitText n/u 0 n/u 0 text limit (#char)
'EM_LineFromChar char# n/u line# containing the character
'EM_LineIndex line# n/u char# of 1st char in the specified line Note: w=-1 is current line
'EM_LineLength char# in line n/u #characters in line Note:
'EM_ReplaceSel T/F if can undo ptr to buffer ?? Note: if no selection, placed at caret
'EM_SetLimitText Max #char's n/u ?? Note: does not affect programmatic char insertion
'EM_SetReadOnly T/F n/u 1-success, 0-failed
'EM_SetSel StartPos EndPos+1 ?? Note: 0/-1 selects all, -1/0 selects none, caret placed at end position
'EM_Undo n/u 0 n/u 0 T-single-line ctrl, T-succes/F-fail for multiline ctrl
'WM_GetText n/u 0 n/u 0 # of characters
'WM_GetTextLength n/u 0 ptr to buffer # of characters in the control
'WM_SetText n/u ptr to buffer True if works, False otherwise
'WM_Undo n/u 0 n/u 0 T-succeeds, F-fails
'EM_AutoURLDetect T/F n/u 0 0-success, non-0-failure
'EM_ExGetSel n/u 0 ptr to CHARRANGE
'EM_ExLimitText n/u 0 Max # char's n/u, Note: does not limit streamin text
'EM_ExLineFromChar n/u char# line#
'EM_ExSetSel n/u ptr to CHARRANGE ??
'EM_FindText flags ptr to FINDTEXT -1 not found, char # of first match
'EM_FindTextEX flags ptr to FINDTEXTEX -1 not found, char # of first match
'EM_GetEventMask n/u 0 n/u 0 Event mask
'EM_GetScrollPos n/u 0 ptr to POINT 1
'EM_GetSelText n/u 0 ptr to buffer # of characters returned
'EM_GetTextEX ptr to GETTEXTEX ptr to buffer ?? Notes: works faster when both lpDefaultChar/lpUsedDefChar are NULL
'EM_GetTextLengthEX ptr to GETTEXTLENGTHEX n/u 0 # of characters in edit control
'EM_GetTextRange n/u 0 ptr to TEXTRANGE # of characters copied
'EM_Redo n/u 0 n/u 0 0-fails, non-0-succeeds
'EM_SetBkgndColor 0, non-zero COLORREF original color Note: COLORREF used if wParam is 0, otherwise uses system color
'EM_SetCharFormat fmt flags ptr to CHARFORMAT 0-fails, non-0-succeeds
'EM_SetEventMask n/u 0 flags default event mask
'EM_SetFontSize size (pts) n/u 0 T-no error, F-error
'EM_SetScrollPos n/u 0 ptr to POINT 1 Note: always displays complete line at top
'EM_SetTextEX ptr to SETTEXTEX ptr to buffer ??
'EM_StreamIn fmt flags ptr to EDITSTREAM # char's read
'EM_StreamOut fmt flags ptr to EDITSTREAM ??
'WM_SetRedraw T/F n/u ---
'gbs_00123
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm