Windows Develop Bookmark and Share   
 index > Windows Forms General > EM_GETLINE
 

EM_GETLINE

Hmm.. does anyone have a working example of using the message EM_GETLINEfrom C# using SendMessage ? I found its code is 0x00C4.
I just cant get it working right.. I know the first char of the wParam should hold the capacity of the buffer andlParam should be the row number..but I just cant get it right ..

Thanks! :)

ShimiIL  Saturday, June 03, 2006 7:03 AM
I agree, why not use Lines[] instead?



// Get the first line of multi-line textBox1
string line1 = textBox1.Lines[0];
MessageBox.Show(line1);

 


It's easier that way. But if you insists on using API to send EM_GETLINE message to your multi-line textbox, then you need to modify your API declaration for SendMessage API and make its lParam as StringBuilder type, like this:



[DllImport("user32.dll", EntryPoint="SendMessageA")]
private static extern int SendMessage_Ex
 (IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);
private const int EM_GETLINE = 0xc4;

 


Then call it this way:



StringBuilder buffer = new StringBuilder(256);
SendMessage_Ex(textBox1.Handle, EM_GETLINE, 0, buffer);
MessageBox.Show(buffer.ToString());

 


Hope this helps,

-chris
Chris Vega  Monday, June 05, 2006 3:51 AM
Why not use TextBox.Lines?
Peter Ritchie  Sunday, June 04, 2006 2:10 AM
I agree, why not use Lines[] instead?



// Get the first line of multi-line textBox1
string line1 = textBox1.Lines[0];
MessageBox.Show(line1);

 


It's easier that way. But if you insists on using API to send EM_GETLINE message to your multi-line textbox, then you need to modify your API declaration for SendMessage API and make its lParam as StringBuilder type, like this:



[DllImport("user32.dll", EntryPoint="SendMessageA")]
private static extern int SendMessage_Ex
 (IntPtr hwnd, int wMsg, int wParam, StringBuilder lParam);
private const int EM_GETLINE = 0xc4;

 


Then call it this way:



StringBuilder buffer = new StringBuilder(256);
SendMessage_Ex(textBox1.Handle, EM_GETLINE, 0, buffer);
MessageBox.Show(buffer.ToString());

 


Hope this helps,

-chris
Chris Vega  Monday, June 05, 2006 3:51 AM
Thanks, I see now where was my problem .. I added ref keyword to an already referenced type StringBuilder ... And had unbalance error ..
Thanks Again !
ShimiIL  Monday, June 05, 2006 3:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Writing to wwwroot folder from Windows Control Library using Log4Net.dll in Web Application
• Interaction w/Access from winForm through Com - Access process will not exit
• DataGridView Scrolling Problem
• Bug
• hide cursor - touchscreen
• how to use OWC in winform?
• drawing problem
• deploying an vb.net 2005 app that creates an excel to a machine with out excel or different version of excel
• Remove ListItem from ListBox
• Setting Form Caption