问题描述
大家好!
i我正在尝试将字符串发送到另一个应用程序。
我尝试这样做的方法是使用windows api中的SendMessage函数,我正在将WParam参数设置为字符串值(当我导入该函数时,我确实使用了此参数的字符串类型)。
现在在接收应用程序中我已将其设置为接收消息并将WParam值的内容放入文本框中,但问题是它没有字符串(我使用了测试字符串Hello World!)它只有一堆数字并将这些数字放入文本框。我在做错了什么?
这里是我在发送应用程序中使用的代码:
这些是我用于SendMessage方法的参数
hello everyone!
i am trying to send a string to another application.
the way i am trying to do this is by using the SendMessage function in the windows api, and i am setting the WParam parameter to a string value(when i imported the function i did use a string type for this parameter).
now in the receiving app i have it setup to receive the message and to put the contents of the WParam value into a textbox, but the problem is it doesn't have a string(i used a test string of "Hello World!") it just has a bunch of numbers and it puts those numbers into the text box. so what am i doing wrong?
here is the code i am using in my sending app:
these are the parameters i am using for the SendMessage Method
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern string SendMessage(int hWnd, int msg, string wParam, IntPtr lParam);
and this line is ran when a button in the form is clicked:
ParentFormHandle = ParentHandle.ToInt32();
SendMessage(ParentFormHandle, 40, "Hello World!", IntPtr.Zero);
这是我在使用的代码复活的应用程序:
this is the code i am using in the reciving app:
protected override void WndProc(ref Message m)
{
if (m.Msg == 40)
{
YourTextBoxNameHere.Text += m.WParam.ToString();
}
else
{
base.WndProc(ref m);
}
}
这里是WParam属性的结果,字符串为Hello World!:
39061140
现在,每当我关闭发送应用程序并再次打开它时,此值将会改变。
如果有人有更好的方法将字符串发送到应用程序请请告诉我。
感谢您提前提供的所有帮助,
MasterCodeon
here is the result of the WParam property with the string "Hello World!":
39061140
now every time i close the sending app and open it back up again this value will change.
if anyone has a better way to send a string to an application please let me know.
thanks for all of your help in advance,
MasterCodeon
推荐答案
//This Is The Wrong Way To Do It
Form newform = new MyFormOne();
//This Is The Correct Way To Do It
MyFormOne newform = new MyFormOne();
当我问这个问题时我不知道我做错了所以我决定使用windows api将字符串发送到另一个应用程序,但不久之后,我意识到我搞砸了并解决了我的问题。
谢谢大家的帮助,
MasterCodeon
when i asked this question i didn't know that i did that wrong so i decided to use the windows api to send a string to another app, but then soon after, i realized i screwed up and fixed my problem.
thank you all for your help,
MasterCodeon
这篇关于C#使用SendMessage函数将字符串发送到另一个Appliaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!