473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SendMessage in VB.Net

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*M MDDYY"
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.

May 18 '07 #1
15 10366
On May 18, 12:38 pm, Necromis <tflem...@pscuf s.comwrote:
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*M MDDYY"

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

May 18 '07 #2
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 18 '07 #3
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 18 '07 #4
"Necromis" <tf******@pscuf s.comschrieb;
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 18 '07 #5
On May 18, 1:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"Necromis" <tflem...@pscuf s.comschrieb;
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
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.

May 18 '07 #6
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.. .

--
Newbie Coder
(It's just a name)
"Necromis" <tf******@pscuf s.comwrote in message
news:11******** *************@l 77g2000hsb.goog legroups.com...
On May 18, 1:29 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrot e:
"Necromis" <tflem...@pscuf s.comschrieb;
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

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.

May 19 '07 #7
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/lib...rs(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/lib...nd(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 [MVP]" <hi************ ***@gmx.atwrote in message
news:ek******** ********@TK2MSF TNGP04.phx.gbl. ..
"Necromis" <tf******@pscuf s.comschrieb;
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 19 '07 #8
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" <ne*********@sp ammeplease.coms chreef in bericht
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
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/lib...rs(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/lib...nd(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 [MVP]" <hi************ ***@gmx.atwrote in message
news:ek******** ********@TK2MSF TNGP04.phx.gbl. ..
>"Necromis" <tf******@pscuf s.comschrieb;
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


May 19 '07 #9
"Newbie Coder" <ne*********@sp ammeplease.coms chrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

May 19 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
19400
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,0,null); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,"11"); response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,null); response =...
3
10157
by: JSK | last post by:
Hi, As any one worked in VB.NET and made use of Sendmessage API? The Issue I am running into is how to pass pointers of Data Structures (UDT) to the SendMessage. I starting looking at "IntPrt" as a data type but it appears to fall short of using pointer types. Any help or insight would be greatly appreciated. Thank You
0
1711
by: SamSpade | last post by:
In my C# library I have many SendMessages like the following: public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref PARAFORMAT2 pf2); I use this one like this:
3
5329
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look at it and let me know what I need to change. I have tried changing the "hwnd" type into intptr's but there seem to be other problems too, like it won't allow "lParam As Any" to be declared.
18
6557
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). Private Declare Auto Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Auto Function FindWindowEx Lib "user32" (ByVal hWnd1 As
3
5085
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. I've got a C# class library project with two classes: Class 1 is derives from : System.Windows.Forms.Form and overrides the base WndProc method for the purpose of receiving and handeling user defined messages:
4
2128
by: Abubakar | last post by:
Hi, My application has a lot of threads which at some point call SendMessage api passing it the handle of the gui window. The calls r a lot. My question is that should I call the SendMessage api by protecting it in a critical section, or the SendMessage api itself handles this kind of situation where a lot of threads in the same process r calling it. Regards,
22
9238
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. I'm sure the problem is the way i'm using the sendmessage API, the return string and the lParam return 0....is anybody have a clue? any sendmessage api expert here? public static extern Int32 FindWindow(String lpClassName,String
1
13406
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by Attachmate. It is a mainframe terminal. Here is the issue and strange part of it. It is accepting sendmessage when I use the WM_KEYDOWN/UP commands. However, when I use WM_SETTEXT to send my string it is not imputing the string to the session...
5
5231
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and marshaling the struct to be able to use it in sendmessage... Here is an example LM_GETITEM: http://msdn.microsoft.com/en-us/library/bb760720(VS.85).aspx
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7381
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.