API (select text)

How can i disable the API for text selecting (mouse & keyboard)?
kort77Asked:
Who is Participating?
 
Answers2000Connect With a Mentor Commented:
If you mean on an Edit control you want to prevent the user selecting text then the way to do it is whenever you get EN_SELCHANGE notification, immediately set the cursor to the beginning of the selection point (by sending EM_SETSEL message to the control).

One thing to watch out for is you're own EM_SETSEL messages may also trigger EN_SELCHANGE notifications (therefore getting you into an infinite loop).  Avoid this by only checking the selection (using EM_GETSEL) and only sending EM_SETSEL whenever something is selected.

0
 
ZifNabCommented:
disabling an API? which one, by name?
0
 
333Commented:
Catch the message and set focus to another component.
0
 
kort77Author Commented:
I need that the code worrks in all the system, not just in one application
0
 
333Commented:
The following code deselects all items in ListBox:

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  SendMessage(ListBox1.Handle,lb_SetCurSel,-1,0);
end;

But there will be a gray rectangle around last selected item. To prevent this add to procedure something like

Button1.SetFocus;

to set focus on another control.
0
All Courses

From novice to tech pro — start learning today.