Ontani Posted June 6, 2004 Posted June 6, 2004 I'v send a message to another window using the sendmessage command. but not i need to send an enter command to the same window. i'v tried SendKeys.Send("{ENTER}") But that only works when the window is active, can someone help me with this one? Greetz From Ontani :cool: Quote www.purevision.be :: www.devpoint.be
Administrators PlausiblyDamp Posted June 8, 2004 Administrators Posted June 8, 2004 http://www.xtremedotnettalk.com/showthread.php?t=78598&highlight=sendmessage Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ontani Posted September 7, 2004 Author Posted September 7, 2004 (edited) well i'm trying to create it again Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32 Private Const WM_SETTEXT As Integer = &HC Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim hwnd As Integer = FindWindow(vbNullString, "Soldier of Fortune 2 Test Console") '/// assuming you have notepad open. Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString) Dim strText As String = "TEST" If Not x = 0 Then SendMessage(x, WM_SETTEXT, 256, strText) End If End Sub This is the code i use. in the textbox in the other window appears the text "TEST" like it should. now it just needs to be entered the window isn't focused so i can't use the send.keys command. in the link you send there not a sollution. so maybe if you have any other ideas? Greetz From Ontani Edited September 7, 2004 by Ontani Quote www.purevision.be :: www.devpoint.be
*Experts* Bucky Posted September 7, 2004 *Experts* Posted September 7, 2004 Send the return characters along with your "TEST", like so: Dim strText As String = "TEST" + Environment.NewLine If that does not work, try sending the Environment.NewLine string in a second call to SendMessage (after sending the "TEST"). Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ontani Posted September 7, 2004 Author Posted September 7, 2004 Environment.NewLine doesn't work. its a text box that needs an ENTER like the enter key, not an newline. the thing you showed me was a linebreak ;) i hope you know what i mean... Greetz Quote www.purevision.be :: www.devpoint.be
*Experts* Bucky Posted September 7, 2004 *Experts* Posted September 7, 2004 In that case, try this (find the value of the constants in the API text viewer): SendMessage(x, WM_KEYDOWN, 13, 1) SendMessage(x, WM_KEYUP, 13, 1) 13 is the code for the return key (I believe) and the 1 is a flag to send the key only once. See more here. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ontani Posted September 7, 2004 Author Posted September 7, 2004 Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32 Private Const WM_SETTEXT As Integer = &HC Private Const WM_KEYDOWN As Integer = &H100 Private Const WM_KEYUP As Integer = &H101 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim hwnd As Integer = FindWindow(vbNullString, "Soldier of Fortune 2 Test Console") '/// assuming you have notepad open. Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString) Dim strText As String = "TESTING AUTOMATIC MESSENGER BY ONTANI" If Not x = 0 Then SendMessage(x, WM_SETTEXT, 256, strText) SendMessage(x, WM_KEYDOWN, 13, 1) SendMessage(x, WM_KEYUP, 13, 1) End If End Sub Ok i'm using this now and still not what i want. this is the window were the messages are send to http://ontani.no-ip.com/server.jpg the text just needs to be entered, i can't get it done. Greetz Quote www.purevision.be :: www.devpoint.be
*Experts* Bucky Posted September 7, 2004 *Experts* Posted September 7, 2004 Hmmm, well according to this site, this might work for you: SendMessage(x, WM_CHAR, 13, 1835009) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ontani Posted September 7, 2004 Author Posted September 7, 2004 MWHoehahahahaha thanx dude, thats it. great man. :p Greetz From Ontani :cool: Quote www.purevision.be :: www.devpoint.be
Ontani Posted September 8, 2004 Author Posted September 8, 2004 now i'm trying to get the text found in the large green textbox. it contains the text : ]status map: mp_shop num score ping name lastmsg address qport rate --- ----- ---- --------------- ------- --------------------- ----- ----- 0 0 0 server 0 127.0.0.1:20100 23656 20000 i just need to read that into a string so i can do some stuff with it. someone and idea? the large green textbox can be viewed in my previous post. Greetz Quote www.purevision.be :: www.devpoint.be
*Experts* Bucky Posted September 8, 2004 *Experts* Posted September 8, 2004 How about sending WM_GETTEXT? Pass the string to receive the text into the lParam, and the maximum length (choose something large) of the string in wParam. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ontani Posted September 8, 2004 Author Posted September 8, 2004 i can't get it to work i do: lResult = SendMessage(x, WM_GETTEXT, 99999999, 1) TextBox1.Text = lResult and the textbox shows 0 this is the window handle of the green area: http://ontani.no-ip.com/window_handle.jpg got any idea whats going wrong? Greetz Quote www.purevision.be :: www.devpoint.be
*Experts* Bucky Posted September 8, 2004 *Experts* Posted September 8, 2004 The problem is that the string is returned not as a return value of the SendMessage method, but as one of its parameters. Also I think your length is too large if the method is returning 0 for a response. Dim sResult As String SendMessage(x, WM_GETTEXT, 10000, sResult) TextBox1.Text = sResult Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Ontani Posted September 9, 2004 Author Posted September 9, 2004 ok now i tried the thing you said. and i'm getting an empty string. so what my guess is as you can see in the window handle http://ontani.no-ip.com/window_handle.jpg is that the little textbox and the large green textbox are both called "Edit" and i think i'm recieving the text from that little textbox. (which one is empty and the large green one isn't). is there another way to specify the window handles? or to select the other textbox. Or maybe something else is wrong... Greetz Quote www.purevision.be :: www.devpoint.be
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.