Cross
Cross

Reputation: 19

Trouble sending message to RichEdit control with winapi c#

Im currently working on a solution for an automation of unmanaged, external code, so im having some trouble setting the text to a RichEdit control.

I have tried sending a WM_SETTEXT but it only sets the first letter of the string to the control.

Other things i have tried: PostMessage, EM_SETTEXTEX, SetWindowText, and i have unsuccessfully tried EM_STREAMIN, but there isn't a simple enough example of that message.

The specific class of the richEdit is: WindowsForms10.RichEdit20W.app.0.141b42a_r14_ad1

My code:

IntPtr Text;
string bar;

...

//Function call
setRichEditText(Text, bar);

...

//Function declaration
private static int setRichEditText(IntPtr hWnd, string text) {
    StringBuilder sb = new StringBuilder(text);
    int result = SendMessage(hWnd, WM_SETTEXT, (IntPtr)sb.Length, sb.ToString());
    return result;
}

...

//Imported function
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);

Is There a way to make it set the whole string or maybe a workaround?

Upvotes: 1

Views: 421

Answers (1)

Cross
Cross

Reputation: 19

finally solved it!

Worked with:

SendMessage(hWnd, WM_SETTEXT, 0, sb.ToString());

Upvotes: 0

Related Questions