簡體   English   中英

無法使用winapi c向RichEdit控件發送消息#

[英]Trouble sending message to RichEdit control with winapi c#

我目前正在研究非托管外部代碼自動化的解決方案,因此我在將文本設置為RichEdit控件時遇到了一些麻煩。

我已經嘗試發送WM_SETTEXT,但它只將字符串的第一個字母設置為控件。

我試過的其他東西:PostMessage,EM_SETTEXTEX,SetWindowText,並且我沒有成功嘗試EM_STREAMIN,但是沒有足夠簡單的消息示例。

richEdit的具體類是:WindowsForms10.RichEdit20W.app.0.141b42a_r14_ad1

我的代碼:

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);

有沒有辦法讓它設置整個字符串或可能是一個解決方法?

終於解決了!

使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM