SetSel

来源:互联网 发布:魔音软件男变女 编辑:程序博客网 时间:2024/05/16 05:06


基本函数原型:

CRichEditCtrl::SetSel  void SetSel( long nStartChar, long nEndChar );  void SetSel( CHARRANGE& cr );  

参数: nStartChar 选择中的第一个字符的从零开始的索引。

  nEndChar 选择中的最后一个字符的从零开始的索引。

  cr 一个CHARRANGE结构,包含了当前选择的界线。

  说明:

  此成员函数用来设置这个CRichEditCtrl对象中的选择。

  这个函数的两种形式都用来设置选择的界线,它们可以相互替换。有关这两种形式的简短描述如下所示: · SetSel( cr ) 这种形式用CHARRANGE结构的cpMin和cpMax成员来设置界线。

  · SetSel( nStarChar, nEndChar ) 这种形式用参数nStartChar和nEndChar来设置界线。

  脱字符号被放置在由开始(cpMin或nStartChar)和结束(cpMax或nEndChar)索引中的较大者所指定的选择的结尾处。此函数不滚动CRichEditCtrl的内容,以使脱字符号是可见的。

  要选择此CRichEditCtrl对象中的索引文本,可以用一个为0的开始索引和一个为-1的结束索引来调用SetSel。

  更多的信息,参见Win32文档中的EM_EXSETSET消息和CHARRANGE结构。

  请参阅:

  CRichEditCtrl::GetSel, CRichEditCtrl::GetSelectionType

  CListBox类成员

  CListBox::SetSel  

int SetSel( int nIndex, BOOL bSelect = TRUE );

  返回值:如果出错,则为LB_ERR。

  参数: nIndex 包含设置的字符串的基于零的索引。如果为-1,选择从所有字符串添加或删除,取决于bSelect值。

  bSelect 指定如何设置选择。如果bSelect为TRUE,字符串被选择并高亮显示;如果为FALSE,高亮显示被去掉且字符串不再被选择。缺省时,指定的字符串被选择并高亮显示。

  说明:

  在多选列表框中选择一个字符串。

  只能对多选列表框使用此成员函数。

  请参阅:CListBox::GetSel, LB_SETSEL

  CEdit类成员

  CEdit::SetSel

  void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE);

  void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = False);

  参数: dwSelection 低位字指定起始位置,高位字为结束位置。如果低位为0,高位为-1,则编辑控件中的全部文本被选中;如果低位字为-1,则任何当前选定内容被去掉选定状态。

  bNoScroll 指示是否显示脱字符是滚动可见的。如果值为FALSE,则显示,TRUE不显示。

  nStartChar 指出当前选中部分的开始位置。如果nStartChar=0且nEndChar=-1,则编辑控件的文本被全选;如果nStartChar=-1,则任何当前选定内容被去掉选定状态。

  nEndChar 指出结束位置。

CEdit::ReplaceSel

调用此函数。lpszNewText指定的文本替换在编辑控件中当前选择。

 
void ReplaceSel(   LPCTSTR lpszNewText,   BOOL bCanUndo = FALSE );
lpszNewText

指向包含替换文本的一个Null终止的字符串。

bCanUndo

若要指定此功能可以取消,请将该参数的值设置为 TRUE默认值为 FALSE

m_ShowInfor.SetSel(-1, -1);//这样可能是全选,也可能是全不选
第一个参数是从第几个记录开始选择,第二个参数是选择到第几个项目,例如m_ShowInfor.SetSel(0, 100);则会把第0~100条记录选上
m_ShowInfor.ReplaceSel(w_str);
应该是把当前选择的项目的字符串替换成w_str的值

用法实例:

m_ShowInfor.SetSel(-1, -1);//这样可能是全选,也可能是全不选
第一个参数是从第几个记录开始选择,第二个参数是选择到第几个项目,例如m_ShowInfor.SetSel(0, 100);则会把第0~100条记录选上
m_ShowInfor.ReplaceSel(w_str);
应该是把当前选择的项目的字符串替换成w_str的值

 

void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
功能:Call this function to select a range of characters in an edit control
调用此函数能在EDIT Control中选择某范围的字符串

参数
nStartChar


Specifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.
指定开始位置,如果nStartChar 为0并且nEndChar 为-1,则选择所有文字,如果nStartChar 为-1,则不选择任何文字

nEndChar

Specifies the ending position.
指定结束位置

Remarks

Call this function to select a range of characters in an edit control.

For more information, seeEM_SETSEL in the Win32 documentation.


void ReplaceSel( LPCTSTR lpszNewText, BOOL bCanUndo = FALSE );

Parameters
参数

lpszNewText

Points to a null-terminated string containing the replacement text.
替换的文字
bCanUndo

To specify that this function can be undone, set the value of this parameter to TRUE . The default value is FALSE.
如果此选项为TRUE,则用户可按Ctrl+Z取消此操作
Remarks

Call this function to replace the current selection in an edit control with the text specified by lpszNewText. 

Replaces only a portion of the text in an edit control. If you want to replace all of the text, use the CWnd::SetWindowText member function. 

If there is no current selection, the replacement text is inserted at the current cursor location.

功能:把所选文字替换成lpszNewText的文字
原创粉丝点击