积极答复者
请问如何在Winform的空白窗口上弹出输入法对话框

问题
答案
全部回复
-
你好,
如果输入英文的话,你可以处理Wndproc方法,去得到WM_CHAR消息以便得到字符。
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
你好,
英文好弄.就是中文不好弄呀..曾用WM_IME_CHAR去判断中文,可是中文输入法不能打开也输不了文字,现在最大的问题是先可以输入文字.请教.
如果输入英文的话,你可以处理Wndproc方法,去得到WM_CHAR消息以便得到字符。
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
那你使用Hotkey去弹出一个定制的Modal Form,这上面使用TextBox控件来得到要画的文字,关闭后再你需要的Form上画好了。
还有你可以不要应用别人的帖子好吗,一般只有特殊的理由再引用(例如有不明白的时候,需要对方澄清的时)。
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
研究一下WM_IME_CHAR消息,应该是从这个消息中取出中文字符:
http://msdn.microsoft.com/en-us/library/dd374132(VS.85).aspx
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
你好,
看下这个帖子,我们需要使用ImmAssociateContext函数把特定的输入上下文和我们的窗口联系起来:
http://bytes.com/topic/net/answers/564476-how-enable-ime-custom-usercontrol
using System.Runtime.InteropServices; public partial class UserControl1 : UserControl { IntPtr m_hImc; public const int WM_IME_SETCONTEXT = 0x0281; [DllImport("Imm32.dll")] public static extern IntPtr ImmGetContext(IntPtr hWnd); [DllImport("Imm32.dll")] public static extern IntPtr ImmAssociateContext(IntPtr hWnd, IntPtr hIMC); public UserControl1() { InitializeComponent(); } private void UserControl1_Load(object sender, EventArgs e) { m_hImc = ImmGetContext(this.Handle); } protected override void WndProc(ref Message m) { base.WndProc(ref m); // the usercontrol will receive a WM_IME_SETCONTEXT message when it gets focused and loses focus respectively // when the usercontrol gets focused, the m.WParam is 1 // when the usercontrol loses focus, the m.WParam is 0 // only when the usercontrol gets focused, we need to call the IMM function to associate itself to the default input context if (m.Msg == WM_IME_SETCONTEXT && m.WParam.ToInt32() == 1) { ImmAssociateContext(this.Handle, m_hImc); } } }
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
非常感谢你.我就只知道用ImmAssociateContext,但就不知道WM_IME_SETCONTEXT这些东西.现在还有一个问题是我用它WM_IME_CHAR取得中文时有一些问题,比如我输入"我"字.打印出来是的"我."i不明白.请指教;我的代码:StringBuilder str = new StringBuilder();int size = ImmGetCompositionString(m_hImc, GCS_COMPSTR, null, 0);size += sizeof(Char);ImmGetCompositionString(m_hImc, GCS_RESULTSTR, str, size);或者还有别的方法取得中文?
-
StringBuilder sb = new StringBuilder();protected override void WndProc(ref Message m){base.WndProc(ref m);switch (m.Msg){case WM_IME_CHAR:StringBuilder str = new StringBuilder();int size = ImmGetCompositionString(m_hImc, GCS_COMPSTR, null, 0);size += sizeof(Char);ImmGetCompositionString(m_hImc, GCS_RESULTSTR, str, size);sb.Append(str.ToString());//MessageBox.Show(str.ToString());intoText();break;}}private void intoText(){Graphics g = this.CreateGraphics();g.DrawString(sb.ToString(), new Font("宋体", 14, FontStyle.Regular), Brushes.Black, 5, 10);}
-
你好,
请给出你的解决方法,以便其他论坛成员可以共享这个好的方法。
Best regards,
Riquel
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. -
已经整理,相关内容请到我的blog上看