SendMessage in VB.Net

N

Necromis

Ok, I am really losing it. I cannot seem to wrap my head around the
SendMessage function/method. What I am trying to do is send text/data
to an instance of a window that I know the handle of from within a
vb.net application. Can someone give me a decent example of the code
I
would need to create to process this using the sample data below.

Windows hwnd = 0xB0484
String text = "NM*14*ACCTNO*MMDDYY"


I have been looking at it both in the local and online help and
searching the web all over and I am not getting it. Either I am not
understanding it right or am missing something. I really right now
just need a good code example. I am trying to pull data from a text
file and send it in strings to another application w/o having to call
focus to the window. This way I can run a batch of transactions on
this other program.


Oh and one other bit of info I am using MS VB 2005 Express Edition as
my coding environment.
 
R

rowe_newsgroups

Ok, I am really losing it. I cannot seem to wrap my head around the
SendMessage function/method. What I am trying to do is send text/data
to an instance of a window that I know the handle of from within a
vb.net application. Can someone give me a decent example of the code
I
would need to create to process this using the sample data below.

Windows hwnd = 0xB0484
String text = "NM*14*ACCTNO*MMDDYY"

I have been looking at it both in the local and online help and
searching the web all over and I am not getting it. Either I am not
understanding it right or am missing something. I really right now
just need a good code example. I am trying to pull data from a text
file and send it in strings to another application w/o having to call
focus to the window. This way I can run a batch of transactions on
this other program.

Oh and one other bit of info I am using MS VB 2005 Express Edition as
my coding environment.

I don't think your can use the SendMessage API to send string
messages. The function only accepts integer values for the message and
lparam and wparam.

Thanks,

Seth Rowe
 
M

Mattias Sjögren

Ok, I am really losing it. I cannot seem to wrap my head around the
SendMessage function/method. What I am trying to do is send text/data
to an instance of a window that I know the handle of from within a
vb.net application.

What kind of window is the target? If it's a standard Windows control
then the WM_SETTEXT message is probably the one you want.


Mattias
 
M

Mattias Sjögren

I don't think your can use the SendMessage API to send string
messages. The function only accepts integer values for the message and
lparam and wparam.

Both lparam and wparam can be any pointer-sized value, including
string pointers etc. What you actually should pass as arguments
depends on the message.


Mattias
 
H

Herfried K. Wagner [MVP]

Necromis said:
Ok, I am really losing it. I cannot seem to wrap my head around the
SendMessage function/method. What I am trying to do is send text/data
to an instance of a window that I know the handle of from within a
vb.net application.

Depending on the exact situation, you may call 'SendMessage' + 'WM_SETTEXT'
(see documentation for details). An alternative would be to call
'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
window handle the text should be assigned to.
 
N

Necromis

Depending on the exact situation, you may call 'SendMessage' + 'WM_SETTEXT'
(see documentation for details). An alternative would be to call
'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
window handle the text should be assigned to.

Well the window is similar to a dos based application. The
applications name is "Extra - For Netware." It is software used by
FDR. We use it in house for transaction processing and I need to key
large batches of transactions to it real time rather than sending them
out to the processor to run.
 
N

Newbie Coder

Necromis,

Don't use SendKeys because if you take focus off the window it will fail

To get the window handle then use the FindWindow function to return the
IntPtr (for 64 bit compatibility) or just Int32 for no 64 bit ones is fine

The WM_SETTEXT is just a constant to use but

What control are you trying to paste to? You mention strings, but for
example Dim strText As String = TextBox1.Text...
 
N

Newbie Coder

Herfried,

[OP QUOTE]:

I am trying to pull data from a text file and send it in strings to another
application w/o having to call focus to the window. This way I can run a
batch of transactions on this other program.

[END OP QUOTE]

[HERFRIED QUOTE]:

An alternative would be to call
'SendKeys.Send'...

[END HERFRIED QUOTE]

How do you use SendKeys to paste text in a window that doesn't have focus?

http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys_members(vs.80).aspx

Look at the definition of SEND in the Public Methods which says:

'Sends keystrokes to the active application'

Notice the 'ACTIVE' application

SendKeys Methods & Examples:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(VS.80).aspx

Where in there does SendKeys pass the handle to send the keystrokes to an
application without focus? There isn't as it only is used for ACTIVE
applications, which the OP didn't want

You're wrong, Herfried

Where's your code examples on using the other information?

You say see WM_SETTEXT constant, but you haven't even supplied simple info
like for example:

Private Const WM_SETTEXT = &HC

----------------------------------------

Sorry, but this proves you shouldn't be a MVP, giving incorrect information
& no code samples

--
Newbie Coder
(It's just a name)
 
M

Michel Posseth [MCP]

why so offensive and rude Newbie Coder ?

Do you have a bad day ? .... I notice this from more people nowadays in
these groups , don`t forget that

Herfried mentioned this as a option , so maybe he means that the OP could
take a alternative aproach
maybe give the app focus send the keystrokes and then set the focus back to
the previous focused app maybe this would become a option for the OP if he
wasn`t aware of this posibility

And well we all have sometimes a bad day ( no bad hairdays for me as i am
bald :)

regards

Michel





Newbie Coder said:
Herfried,

[OP QUOTE]:

I am trying to pull data from a text file and send it in strings to
another
application w/o having to call focus to the window. This way I can run a
batch of transactions on this other program.

[END OP QUOTE]

[HERFRIED QUOTE]:

An alternative would be to call
'SendKeys.Send'...

[END HERFRIED QUOTE]

How do you use SendKeys to paste text in a window that doesn't have focus?

http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys_members(vs.80).aspx

Look at the definition of SEND in the Public Methods which says:

'Sends keystrokes to the active application'

Notice the 'ACTIVE' application

SendKeys Methods & Examples:

http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(VS.80).aspx

Where in there does SendKeys pass the handle to send the keystrokes to an
application without focus? There isn't as it only is used for ACTIVE
applications, which the OP didn't want

You're wrong, Herfried

Where's your code examples on using the other information?

You say see WM_SETTEXT constant, but you haven't even supplied simple info
like for example:

Private Const WM_SETTEXT = &HC

----------------------------------------

Sorry, but this proves you shouldn't be a MVP, giving incorrect
information
& no code samples

--
Newbie Coder
(It's just a name)




Herfried K. Wagner said:
Depending on the exact situation, you may call 'SendMessage' + 'WM_SETTEXT'
(see documentation for details). An alternative would be to call
'SendKeys.Send' or 'keybd_event' or 'SendInput', if you do not have the
window handle the text should be assigned to.
 
H

Herfried K. Wagner [MVP]

Newbie Coder said:
Don't use SendKeys because if you take focus off the window it will fail

Whereas the latter is true, I believe that 'SendKeys' serves its purpose.
To get the window handle then use the FindWindow function to return the
IntPtr (for 64 bit compatibility) or just Int32 for no 64 bit ones is fine

The WM_SETTEXT is just a constant to use but

What control are you trying to paste to? You mention strings, but for
example Dim strText As String = TextBox1.Text...

'WM_SETTEXT' won't work for all controls/windows, that's why I mentioned
'SendKeys' as an alternative for those cases. Well, yes, I know about the
disadvantages of this approach very well.
 
C

Cor Ligthert [MVP]

Herfried,

With one short sentence you destroy the work from Michel.

You should know that Newbie Coder is no troll any more but a welcome
contributer.

I think with this I have enough written,

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
With one short sentence you destroy the work from Michel.

You should know that Newbie Coder is no troll any more but a welcome
contributer.

If somebody acts like a troll, he is a troll.

Nevertheless, constructive and helpful contributions are always welcome and
valuable.
 
N

Necromis

Thank you all, the help is appreciated, and hopefully in the end we
will have the answer I need. The application is MS-Dos based, it
utilizes ODS as well. Also the main window I am sending the text
string to is similar in function to cmd prompt screen. I have the
handle of the window which I included in my earlier post.
 
N

Newbie Coder

Necromis,

The handle isn't static & will change at each run or boot

So, you need to pass a string to a console app. How many command line
arguments are there?

In the first app, where is the text coming from? A textbox or another
control or another?

Does it have to destroy the data after its sent?
 
N

Necromis

Ok, here is the full break down of what I am working on. I am trying
to build an app that will import tab delimited text. Then with that
information I need to send repetitive strings of text to the MS-Dos
based application. Think of it like taking in a bunch of basic
information about individuals and then adding additional "constants"
and then spitting it out as a string to the other application. Like if
the text file contained "Bob" "Blue" "Cat" and after adding the
constants sending "Bob prefers the color blue and owns a pet cat." I
have the data supplied by WinID for the window I need the text to be
sent to as well as the application. I don't need the data destroyed
after it is sent, due to when I send the data and send a [Enter]
command it will be over-written by the next string of text. I know the
application also is compatible with OLE. The true lay out of my string
will end up like the below but with a customer account number and a
date in that format being passed. The last value that needs to be
passed at the end of each string will be an [Enter] command.

String text = "NM*14*ACCTNO*MMDDYY"

Please let me know what information you need about class, title and
what not I have gathered from WinID. (similar to spy++)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

SendMessage WM_SETTEXT Issues 1
SendMessage in VB.NET 5
SendMessage WM_COPYDATA on 64bit System 1
SendMessage and WM_SETTEXT 3
Call SendMessage API Question 16
SendMessage() 2
SendMessage API 3
Manage SendMessage 3

Top