Results 1 to 5 of 5

Thread: How to simulate 'select all' trough API

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175

    Question How to simulate 'select all' trough API

    Hi all,

    I want to know if there is an API to use instead of Control_A.

    I mean select all the text in a text area (not your own app) without sending the Control+A


    Regards;
    Mass

  2. #2
    Lively Member
    Join Date
    Apr 2003
    Posts
    114
    .

    I did not test this, but may be worth a shot. Lookup EM_SETSEL.
    VB Code:
    1. 'May want to experiment with parameter datatypes of SendMessage.  Could make them integers.
    2. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4. Public Const EM_SETSEL = &HB1
    5.  
    6. Dim Res as Long, hWnd as long, SelStart as long=0,SelEnd as Long=6
    7. Res = SendMessage(hWnd,EM_SETSEL,SelStart,SelEnd)
    8. 'NOTE - You could use WM_GETTEXTLENGTH to find out how many characters are in the edit control
    9.  
    10. '// returns LRESULT in
    11. 'lResult = SendMessage(
    12.   '(HWND) hWndControl,      // handle to destination 'control    
    13.   '(UINT) EM_SETSEL,      // message ID    
    14.   '(WPARAM) wParam,      // Start Character Position;
    15.   '(LPARAM) lParam      // End Character Position );
    I can do all things with VB.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    It would be great if you can help

    I'm trying to grab text from a program which apparently is written in Delphi. The control class is a Tpanel.

    Could you help please?

    Regards;
    Mass

  4. #4
    Lively Member
    Join Date
    Apr 2003
    Posts
    114
    The first thing you have to do is get the handle of the control you want. This can be done several ways, but the best method depends on how you want your program to run.

    If as a rule, the other program will be running and has the focus then using the api ChildWindowFromPoint may be good.

    Now, you have to do some preliminary things to get to that point.

    Ex:

    VB Code:
    1. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Public Declare Function ChildWindowFromPoint Lib "user32" Alias "ChildWindowFromPoint" (ByVal hWndParent As Long, ByVal pt As POINT) As Long
    3. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4.  
    5. Public Const EM_SETSEL = &HB1
    6.  
    7. Dim Res as Long, SelStart as long=0,SelEnd as Long=6
    8.  
    9. 'Pass in the window titlebar value of the other program.
    10. dim Handle as Long = FindWindow("","Titlebar Text") 'example only
    11.  
    12. 'The window that you want to select text will most likely always be in the same position relative to the parent.  So, figure out the relative coordinates of the window.  
    13. dim pt as New Point(75,90) 'example
    14. dim TextHandle as long = ChildWindowFromPoint(Handle,pt)
    15. Res = SendMessage(TextHandle,EM_SETSEL,SelStart,SelEnd)

    Maybe someone else will have a cleaner way.
    I can do all things with VB.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Posts
    175
    Thanks,

    I tried the code but it didn't work, any other suggestion?

    I must add that the text I'm trying to grab can be selected and copied, the problem is when I send control+A it will have a popup window wich dose not allow me to select all the text

    Rehards;
    Mass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width