Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

  • 2 months later...
Posted (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 by Ontani
  • *Experts*
Posted

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").

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

   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

  • *Experts*
Posted

Hmmm, well according to this site, this might work for you:

 

SendMessage(x, WM_CHAR, 13, 1835009)

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted

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

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...