1

Thanks to Rob Kennedy's answer to my question on how to set the Skype Chat window text.

However, whenever I set the text using

SendMessage(RichEditWnd,WM_SETTEXT,0,Integer(PChar(Edit1.Text)));

Then when I click on the Chat Edit control in Skype, the carret is placed at the beginning and some clicking is required to get it "right" again.

Is there a Windows Message for setting the carret position? Or atleast something that I can use to set the Carret Position to the end of the text? :)

Community
  • 1
  • 1
Jeff
  • 12,085
  • 12
  • 82
  • 152

1 Answers1

3

Yes, there is: EM_EXSETSEL.

wParam should be 0, and lParam should be a pointer to a TCharRange structure containing the first and last characters in the selection. You want these to be equal (that is, zero characters selected).

For instance,

var
  cr: TCharRange;
begin
  cr.cpMin := 2;
  cr.cpMax := 2;
  SendMessage(RichEdit1.Handle, EM_EXSETSEL, 0, integer(@cr));

will set the caret just before the third character in the Rich Edit control.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384