Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Sets the selection within this CRichEditCtrl object.

void SetSel(
   long nStartChar,
   long nEndChar 
void SetSel(



Zero-based index of the first character for the selection.


Zero-based index of the last character for the selection.


CHARRANGE structure which holds the bounds of the current selection.

The two forms of this function provide alternate ways to set the bounds for the selection. Brief descriptions of these forms follow:

  • SetSel( cr )   This form uses the CHARRANGE structure with its cpMin and cpMax members to set the bounds.

  • SetSel( nStartChar , nEndChar )   This form use the parameters nStartChar and nEndChar to set the bounds.

The caret is placed at the end of the selection indicated by the greater of the start (cpMin or nStartChar) and end (cpMax or nEndChar) indices. This function scrolls the contents of the CRichEditCtrl so that the caret is visible.

To select all the text in this CRichEditCtrl object, call SetSel with a start index of 0 and an end index of – 1.

For more information, see EM_EXSETSEL message and CHARRANGE structure in the Platform SDK.

See the example for GetSel.

© 2015 Microsoft