This documentation is archived and is not being maintained.


Retrieves the bounds of the current selection in this CRichEditCtrl object.

void GetSel(
) const;
void GetSel(
   long& nStartChar,
   long& nEndChar 
) const;



Reference to a CHARRANGE structure to receive the bounds of the current selection.


Zero-based index of the first character in the current selection.


Zero-based index of the last character in the current selection.

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

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

  • GetSel( nStartChar , nEndChar )   This form returns the bounds in the parameters nStartChar and nEndChar.

The selection includes everything if the beginning (cpMin or nStartChar) is 0 and the end (cpMax or nEndChar) is – 1.

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

// The pointer to my rich edit control.
extern CRichEditCtrl* pmyRichEditCtrl;

// Set the selection to be all characters after the current selection.
long nStartChar, nEndChar;

pmyRichEditCtrl->GetSel(nStartChar, nEndChar); 
pmyRichEditCtrl->SetSel(nEndChar, -1);