can't use SendMessage_EX twice in my c# program

前端 未结 1 1867
野趣味
野趣味 2021-01-24 10:25

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:



        
相关标签:
1条回答
  • 2021-01-24 11:11

    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());
    
    0 讨论(0)
提交回复
热议问题