|
-
Feb 23rd, 2002, 11:40 PM
#1
Thread Starter
Lively Member
SendMessage API Sending Enter Key How? Help!
Ok How do I do this, I am trying to send the enter key to a combo box after I change the text in it.
I have an old legacy app i am trying to convert over and well i am trying to automate the data entry process and I am almost done but I am having a problem with one part. Also this is a vb application controlling another Application which is why I am doing some crazy crap here
Basically I have a combo box that allows me to enter text into it hence creating another option however before it becomes a valid option you must hit the enter key
Here is the current code I am using for this in a module and it works as far as entering in the text I just cant get it to hit the enter key
Code:
Public Const WM_SETTEXT = &HC
Public Const WM_CHAR = &H102
Public Const ENTER_KEY = 13
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) 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
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Sub EnterCombo(txtToEnter As String)
Dim Edit As Long
Dim ComboBox As Long
Dim MyProg As Long
MyProg = FindWindow("Flex Account", vbNullString)
ComboBox = FindWindowEx(MyProg, 0, "ComboBox", vbNullString)
Edit = FindWindowEx(ComboBox, 0, "Edit", vbNullString)
Call SendMessageByString(Edit, WM_SETTEXT, 0&, txtToEnter)
Call SendMessageLong(Edit, WM_CHAR, ENTER_KEY, 0&)
End Sub
Last edited by BOUND4DOOM; Feb 23rd, 2002 at 11:45 PM.
The secret to creativity is knowing how to hide your sources.
-- Albert Einstein
-
Feb 25th, 2002, 12:24 AM
#2
Fanatic Member
Hi
Use
After finding the window.. get it to foreground and then use
Sendkey "{enter}"
Let me know if you can do it.. else i will give you the code..
Pradeep
-
Feb 25th, 2002, 04:56 PM
#3
Thread Starter
Lively Member
Yeah that is what I ended up doing. I was trying to get it going without using appactivate and bringing it to the front but couldn't get it to work I did find code after searching all week end on some abstract VB message board somewhere using the postmessage API but it didn't work with this old program, worked fine in Notepad I tested it there but not mine.
I would love to be able to do that though if you can show me another way after I describe the problem
When I finally got it to work believe it or not by using send key and basically going in and creating a hot key in the program to do what I want and then sending the hot key to the application, So I did get it to work.
The Problem with it still.
Now Tab key works and Hot Keys Work even sending text but when I send the enter key for some damn reason the text in the field I am sending enter too changes to
.e
And then the enter key never gets pushed. I think there is more too it than just sending enter here now. I know I can get by with the hot key thing I prefer not to.
Basically to give you a idea there is like almost 3 windows on one form you can hit tab to cycle to which window you want and it becomes the active window. And like I said Tab works. When you tab to different windows. The window you are on lights up a frame. just to let you know which window you are on.
When you hit enter with your keyboard on the window I am trying to change it submits the text you have selected in the combo box or entered in it, however then it sets your main window back to active so Maybe I am just sending enter back to the wrong spot, I dunno the biggest problem is trying to figure out what that damn enter key is really doing, and which form it is submitting too, any idea, or know of an application that will record what that is doing and be able to reproduce it, I have tried Spy ++ but which window to watch or what ever is baffling me and hitting enter no matter what window I am monitoring looks like it does something in there.
I have tried just sending enter to the main window but still doesn't work. When you are just sitting there after opening it up or the main frame I described the mini windows inside, when that is selected hitting enter open up another form. I can also right click on it, however I have no idea how to send right click commands and stuff. Any Help there would be nice too. because I may end up having to do that later with something else.
Last edited by BOUND4DOOM; Feb 25th, 2002 at 05:04 PM.
The secret to creativity is knowing how to hide your sources.
-- Albert Einstein
-
Feb 27th, 2002, 06:13 AM
#4
New Member
sorry cant help you with that... but maybe you can help me with my problem Bound4Doom :P
You mentioned you came across a working example/code to send key/string to Notepad using PostMessage. Could you please direct me to where i could find that code? or attach/paste it here?
Thanx :\
-
Mar 1st, 2002, 11:08 AM
#5
Thread Starter
Lively Member
Yeah I will do it tonight, sorry just got back here to check the post, I have it bookmarked at home where I found it and then downloaded it and tried it out, I may be able to find it in a few I think I was given the link to it or got the link from another site that someone posted the link to before. I will look for it again. If I cant find it then I know I saved it at home
The secret to creativity is knowing how to hide your sources.
-- Albert Einstein
-
Mar 1st, 2002, 07:42 PM
#6
New Member
great, thnx
tyt
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
|