VS2005IDE中输入法全角[控制输入问题]
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Runtime.InteropServices;
9![]()
10namespace Lqjt
11{
12public partial class ImeForm : Form
13{
14public ImeForm()
15{
16InitializeComponent();
17}
18//声明一些API函数
19[DllImport("imm32.dll")]
20public static extern IntPtr ImmGetContext(IntPtr hwnd);
21[DllImport("imm32.dll")]
22public static extern bool ImmGetOpenStatus(IntPtr himc);
23[DllImport("imm32.dll")]
24public static extern bool ImmSetOpenStatus(IntPtr himc, bool b);
25[DllImport("imm32.dll")]
26public static extern bool ImmGetConversionStatus(IntPtr himc, ref int lpdw, ref int lpdw2);
27[DllImport("imm32.dll")]
28public static extern int ImmSimulateHotKey(IntPtr hwnd, int lngHotkey);
29private const int IME_CMODE_FULLSHAPE = 0x8;
30private const int IME_CHOTKEY_SHAPE_TOGGLE = 0x11;
31protected override void OnActivated(EventArgs e)
32{
33base.OnActivated(e);
34IntPtr HIme = ImmGetContext(this.Handle);
35if (ImmGetOpenStatus(HIme)) //如果输入法处于打开状态
36{
37int iMode = 0;
38int iSentence = 0;
39bool bSuccess = ImmGetConversionStatus(HIme, ref iMode, ref iSentence); //检索输入法信息
40if (bSuccess)
41{
42if ((iMode & IME_CMODE_FULLSHAPE) > 0) //如果是全角
43ImmSimulateHotKey(this.Handle, IME_CHOTKEY_SHAPE_TOGGLE); //转换成半角
44}
45![]()
46}
47}
48}//form
49}