VS2005IDE中输入法全角[控制输入问题]

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