日期:2014-05-18 浏览次数:20853 次
//光标API [DllImport("user32.dll")] static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight); [DllImport("user32.dll")] static extern bool ShowCaret(IntPtr hWnd); [DllImport("User32.dll")] static extern bool HideCaret(IntPtr hWnd); [DllImport("User32.dll")] static extern bool SetCaretPos(int x, int y); [DllImport("user32.dll")] static extern bool DestroyCaret(); //输入法相关API public const int WM_IME_SETCONTEXT = 0x0281; private const int WM_IME_CHAR = 0x0286; private const int WM_CHAR = 0x0102; private const int WM_IME_COMPOSITION = 0x010F; private const int GCS_COMPSTR = 0x0008; [DllImport("Imm32.dll")] public static extern IntPtr ImmGetContext(IntPtr hWnd); [DllImport("Imm32.dll")] public static extern IntPtr ImmAssociateContext(IntPtr hWnd, IntPtr hIMC); [DllImport("imm32.dll")] static extern int ImmGetCompositionString(IntPtr hIMC, int dwIndex, StringBuilder lPBuf, int dwBufLen); private int GCS_RESULTSTR = 0x0800; private const int HC_ACTION = 0; private const int PM_REMOVE = 0x0001; //大概处理过程 protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_IME_SETCONTEXT && m.WParam == (IntPtr)1) { ImmAssociateContext(this.Handle, m_hImc); } switch (m.Msg) { case WM_CHAR: char a = (char)m.WParam; //英文 //............... break; case WM_IME_CHAR: if (m.WParam.ToInt32() == PM_REMOVE) { int size = ImmGetCompositionString(m_hImc, GCS_COMPSTR, null, 0); size += 2; ImmGetCompositionString(m_hImc, GCS_RESULTSTR, str, size); //.............. } break; } }
------解决方案--------------------
是这个链接http://webservices.ctocio.com.cn/net/92/9142592.shtml