Setting the mouse position of a textbox.

Posted on 2004-11-22
Last Modified: 2010-04-05
Hey, this is what I want to do.

I have the handle of another textbox of another program. When I edit the text of that textbox by doing a SETTEXT on the handle then the mouse position goes to 0 (i.e: to the beginnen of the text), what I want is to send a message after the SETTEXT so that the mouse position goes to the end of the text like it was.

Question by:JimmyJJ
    LVL 6

    Expert Comment

    do you want to set the mouse position or the text caret ?

    Author Comment

    Yup the last thing you mentioned. Any ideas?

    LVL 17

    Accepted Solution


    Try this:

      h: THandle;
      s: string;
      s := 'text for setting';
      h := .. // get the handle
      ... //send WM_SETTEXT here
      SendMessage(h, EM_SETSEL, Length(s), Length(s));
      SendMessage(h, EM_SCROLLCARET, 0, 0);

    Regards, Geo
    LVL 17

    Expert Comment

    EM_SETSEL will position the cursor at the end of the text
    EM_SCROLLCARET will scroll to the cursor in a multiline control

    Author Comment

    Hey, thnx man!

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
    Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now