Results 1 to 10 of 10

Thread: Sendkeys V Sendmessage

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    93

    Sendkeys V Sendmessage

    I have been trying to replace Sendkeys with Sendmessage but I am having a few problems.

    Example of old sendkeys code :

    PHP Code:

    App
    .Activate "Title of other application"
    Sendkeys "^o" "~"TRUE
    Sendkeys 
    "filename" "~"TRUE
    DoEvents 
    This code seems to work (sometimes)

    The Sendmessage code I am using is as follows :

    PHP Code:

    Public Const WM_SETTEXT = &HC

    Private Declare Function GetForegroundWindow _
    Lib 
    "user32" () As Long

    Public Declare Function SetForegroundWindow Lib "user32" _
        
    (ByVal hwnd As Long) As Long

    Public Declare Function SendMessage Lib "user32" _
        Alias 
    "SendMessageA" _
        
    (ByVal hwnd As Long_
        ByVal wMsg 
    As Long_
        ByVal wParam 
    As Long_
        lParam 
    As Any) As Long

    SetForegroundWindow otherapp
    .hWnd
    SendMessage otherapp
    .hWndWM_SETTEXT0By Val "^o"
    SendMessage GetForegroundWindowWM_SETTEXT0By Val "filename" 
    My problem is that using the sendmessage changes the window caption/title of the other application instead of pass in the keystrokes.

    What am I doing wrong or should I give up on sendmessage and stick to sendkeys?

  2. #2
    What are you trying to achieve using Sendmessage rather than SendKeys?

  3. #3
    DaoK
    Guest
    Yes he try to do that

  4. #4
    Originally posted by DaoK
    Yes he try to do that
    No, I mean what is the advantage of using Sendmessage over SendKeys?

  5. #5
    DaoK
    Guest
    Sendkey is more easy ? Am I right?

  6. #6
    IMHO it IS much easier. Maybe he was trying to get a speed advantage or something.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    93
    With sendkeys if the active application that you are sending the keys too looses focus, things can go out of control.

    From what I can read, sendmessage is a more reliable method.

    I have cases where I have multiple send keys (like about 10 in a row) because I need to perform a task in another application and I am using sendkeys to automate this process. The major problem sendkeys can screw up sometimes and I want to use something that will work everytime, even if the user click's another window.

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Sendkeys V Sendmessage

    Originally posted by Skreen
    My problem is that using the sendmessage changes the window caption/title of the other application instead of pass in the keystrokes.

    What am I doing wrong or should I give up on sendmessage and stick to sendkeys?
    The problem is that it is working, just not the way you wanted to . If you pass SendMessage the hWnd of a window, it will change the caption. To "send" keystrokes, you will need to get the handle of the textbox or whatever. There was a thread about this a couple of weeks ago, I will look around for it.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    93
    If I know the hWnd of the parent window (i.e. the application window), how can I find the handle to the child window that has the focus (i.e. the text box or command button etc)

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