能否抓到trichedit中的光标位置?(100分)

  • 主题发起人 主题发起人 O_O
  • 开始时间 开始时间
O

O_O

Unregistered / Unconfirmed
GUEST, unregistred user!
我想知道TRichEdit中的光标位置,有办法实现吗?该位置在TRichEdit失去焦
点时也可以知道吗?
 
SelStart和CaretPos.
selStart应该与焦点无关.
 
Hehe, I can tell how to get it in VC,
you can find the proper way in Delphi also:

// Let's suppose hRTFWnd is the handle of your RichEdit
int iRow, iCol;
CHARRANGE cr;

// Find out the position of the caret (if a selection is set,
// use the endpoint of the selection).
SendMessage( hRTFWnd, EM_EXGETSEL, 0, (LPARAM)&cr );

// Figure the row and column
iRow = (int)SendMessage( hRTFWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)(cr.cpMax) );
iCol = (int)(cr.cpMax - (int)SendMessage ( hRTFWnd, EM_LINEINDEX, iRow, 0 ) );
 
你根本不用担心,RichEdit不管是否焦点均支持 SELSTART!
我的程序查找和选定文本全是用的的SELSTART
语法当然就是
1. with Richedit do
SelStart:= ... & GetMyStartPos:=SelStart
2.Richedit.SelStart:=... & GetMyStartPos:=Richedit.SelStart
 
多人接受答案了。
 
后退
顶部