5

SendMessage这是我使用该函数填充文本框的代码:

  C := 'Hey there';
  SendMessage(h1, WM_SETTEXT, 1, Integer(PChar(C)));

现在,如何将光标移动到文本的末尾?

4

2 回答 2

19

If you really want to do this with messages take a look at:

  1. EM_SETSEL
  2. EM_EXSETSEL

Also there you have the complete reference for edit:

http://msdn.microsoft.com/en-us/library/ff485923%28v=VS.85%29.aspx

In code (no messages) you would do something like this:

Edit1.SelLength := 0;
Edit1.SelStart := 0;   // set caret before first character
...
Edit1.SelStart := 1;   // set caret before second character
...
Edit1.SelStart := Length(Edit1.Text) // set caret after the last character

With messages:

SendMessage(h1, EM_SETSEL, Length(C), Length(C));
于 2010-10-08T04:51:53.643 回答
1

我认为你的代码是错误的。你必须使用“EM_SETSEL”参数。我的问题用这段代码解决了:

  //Set a value for external textbox
  SendMessage(h1, WM_SETTEXT, 0, Integer(PChar(C)));
  //move the cursor to end of the textbox(editbox,field,...)
  SendMessage(h1, EM_SETSEL, length(C), length(C));

还是非常感谢 :)

于 2010-10-08T05:56:57.233 回答