|
-
Oct 10th, 2001, 07:07 PM
#1
Thread Starter
Lively Member
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.hWnd, WM_SETTEXT, 0, By Val "^o"
SendMessage GetForegroundWindow, WM_SETTEXT, 0, By 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?
-
Oct 10th, 2001, 07:08 PM
#2
Member
What are you trying to achieve using Sendmessage rather than SendKeys?
-
Oct 10th, 2001, 07:22 PM
#3
-
Oct 10th, 2001, 07:22 PM
#4
Member
Originally posted by DaoK
Yes he try to do that
No, I mean what is the advantage of using Sendmessage over SendKeys?
-
Oct 10th, 2001, 07:26 PM
#5
Sendkey is more easy ? Am I right?
-
Oct 10th, 2001, 07:27 PM
#6
Member
IMHO it IS much easier. Maybe he was trying to get a speed advantage or something.
-
Oct 10th, 2001, 07:41 PM
#7
Thread Starter
Lively Member
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.
-
Oct 10th, 2001, 07:45 PM
#8
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
-
Oct 10th, 2001, 07:47 PM
#9
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Oct 11th, 2001, 06:35 AM
#10
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|