我想设置编辑控件的文本。当我这样做的时候,新内容是中文。
例如:
[DllImport("user32.dll")]
public static extern int SendMessageW([InAttribute] System.IntPtr hWnd, int Msg, int wParam, string lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr GetFocus();
IntPtr c = GetFocus();
SendMessageW(c, 12, 0, "Test"); //Notice that 12 = WM_SETTEXT
将我的编辑控件设置为:敔瑳
根据pinvoke.net,您需要字符串参数上的MarshalAs
属性:
[DllImport("user32.dll")]
public static extern int SendMessageW(
[InAttribute] System.IntPtr hWnd,
int Msg,
int wParam,
[MarshalAs(UnmanagedType.LPWStr)] string lParam);