Search code examples
delphicaretdelphi-6text-cursor

X,Y coordinates of text cursor position


How to find out X,Y screen coordinates of a text cursor in a control whatever is focused at current time? It may be TEdit, TMemo or any other control with text cursor.

I need it in order to display a window with a choice of alternative characters user can enter. This window should pop up on a special key combination, with its top left corner near to the caret in currently active editor. Because I did'nt want to make individual processing for each editing control, I do it application wide in Application.OnMessage handler.


Solution

  • GetCaretPos can do the trick.

    It works like

    if Windows.GetCaretPos(cp) and Windows.ClientToScreen(GetFocus(), cp) then begin
      //.......
    end;