在我的C#程序不能使用SendMessage_EX两次 [英] can't use SendMessage_EX twice in my c# program

查看:129
本文介绍了在我的C#程序不能使用SendMessage_EX两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临一个很奇怪的问题,无法揣摩出的错误。我使用SendMessage_EX获得指定行的文本:



<预类=郎-CS prettyprint-覆盖> SendMessage_Ex(hr.Handle,EM_GETLINE湖,缓冲液);



然后我调用该方法两次这样的:



<预类=郎-CS prettyprint-覆盖> StringBuilder的缓冲=新的StringBuilder(256);
SendMessage_Ex(hr.Handle,EM_GETLINE,5,缓冲);
StringBuilder的缓冲器1 =新的StringBuilder(256);
SendMessage_Ex(hr.Handle,EM_GETLINE,4,缓冲器1);



它得到第5行的文本正确,但随后的4号线,它没有返回值(缓冲器1为空) 。
。如果我扭转它和第一个GET 4号线,然后第5行,它返回第4行,没有什么对5号线的文本。



这是非常奇怪的,我敢肯定,我做一个简单的错误,但如果是错误的?
我感谢所有帮助。 :)


解决方案

的EM_GETLINE消息希望在它使用的缓冲液相同的参数传递的缓冲区的大小。我不能只是设置0指数的StringBuilder没有它初始化为某个值(有一个索引除外)



这似乎工作:

  StringBuilder的缓冲=新的StringBuilder(,256); 
缓冲液[0] =(char)的256;
INT结果= SendMessage_Ex(textBox1.Handle,EM_GETLINE,3,缓冲区);

StringBuilder的缓冲器1 =新的StringBuilder(,256);
缓冲器1 [0] =(char)的256;
INT结果1 = SendMessage_Ex(textBox1.Handle,EM_GETLINE,2,缓冲器1);

MessageBox.Show(buffer.ToString());
MessageBox.Show(buffer1.ToString());


I am facing a very strange problem and couldn't figure out where's the mistake. I'm using SendMessage_EX to get a specified line's text:

SendMessage_Ex(hr.Handle, EM_GETLINE, l, buffer);

then I call the method twice like this:

StringBuilder buffer = new StringBuilder(256);
SendMessage_Ex(hr.Handle, EM_GETLINE, 5, buffer);
StringBuilder buffer1 = new StringBuilder(256);
SendMessage_Ex(hr.Handle, EM_GETLINE, 4, buffer1);

It gets text of line 5 correctly but then for line 4, It returns nothing(buffer1 is empty). If I reverse it and first get line 4 and then line 5, It returns the text of line 4 and nothing for line 5.

It's very strange and I'm sure I'm making a simple mistake, but where is the mistake? I appreciate any help. :)

解决方案

The EM_GETLINE message wants the size of the buffer passed in the same parameter it uses for a buffer. I couldn't just set the 0 index of the StringBuilder without initializing it to some value (got an index exception).

This seems to work:

StringBuilder buffer = new StringBuilder("   ", 256);
buffer[0] = (char)256;   
int Result = SendMessage_Ex(textBox1.Handle, EM_GETLINE, 3, buffer);

StringBuilder buffer1 = new StringBuilder("   ", 256);
buffer1[0] = (char)256;
int Result1 = SendMessage_Ex(textBox1.Handle, EM_GETLINE, 2, buffer1);

MessageBox.Show(buffer.ToString());
MessageBox.Show(buffer1.ToString());

这篇关于在我的C#程序不能使用SendMessage_EX两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆