//看看Delphi的TCustomRich,TCustomMemo,TCustomEdit的原码,里面有很多这方面的技巧
CharRange: TCharRange;
SendMessage(Handle, EM_EXGETSEL, 0, Longint(@CharRange)) //得到选择的文本
//设置选择的开始
CharRange.cpMin := Value;
CharRange.cpMax := Value;
SendMessage(Handle, EM_EXSETSEL, 0, Longint(@CharRange));
//设置选择的长度
SendMessage(Handle, EM_EXGETSEL, 0, Longint(@CharRange));
Result := CharRange.cpMax - CharRange.cpMin;
//替换选择的字符 Value:string
SendMessage(Handle, EM_REPLACESEL, 0, Longint(PChar(Value)));