WM_SETTEXT写中文字母 [英] WM_SETTEXT writes chinese letters

查看:465
本文介绍了WM_SETTEXT写中文字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置编辑控件的文本。当我这样做时,新内容是中文。

例如,这个:

I want to set the text of my Edit Control. When I do, the new content is Chinese.
For example, this:

[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。网 [ ^ ],你需要字符串参数的 MarshalAs 属性:

According to pinvoke.net[^], you need a MarshalAs attribute on the string parameter:
[DllImport("user32.dll")]
public static extern int SendMessageW(
    [InAttribute] System.IntPtr hWnd, 
    int Msg, 
    int wParam, 
    [MarshalAs(UnmanagedType.LPWStr)] string lParam);


这篇关于WM_SETTEXT写中文字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆