Example #1
0
 /// <summary>
 /// Disable the IME
 /// </summary>
 public void disableIME()
 {
     IsEnabled = false;
     IMM.ImmAssociateContext(Handle, IntPtr.Zero);
 }
        protected override void WndProc(ref Message message)
        {
            if (message.Msg == WindowMessage.InputLanguageChange)
            {
                return;
            }

            if (message.Msg == WindowMessage.ImeSetContext)
            {
                if (message.WParam.ToInt32() == 1)
                {
                    IntPtr imeContext = IMM.ImmGetContext(this.Handle);
                    if (context == IntPtr.Zero)
                    {
                        context = imeContext;
                    }
                    IMM.ImmAssociateContext(this.Handle, context);
                }
            }
            base.WndProc(ref message);

            switch (message.Msg)
            {
            case (int)WindowMessages.WM_GETDLGCODE:
            {
                if (Is32Bit)
                {
                    int returnCode = message.Result.ToInt32();
                    returnCode    |= (DLGC_WANTALLKEYS | DLGC_WANTCHARS);
                    message.Result = new IntPtr(returnCode);
                }
                else
                {
                    long returnCode = message.Result.ToInt64();
                    returnCode    |= (DLGC_WANTALLKEYS | DLGC_WANTCHARS);
                    message.Result = new IntPtr(returnCode);
                }

                break;
            }

            case (int)WindowMessages.WM_CHAR:
            {
                int       charInt     = message.WParam.ToInt32();
                Character myCharacter = new Character();
                myCharacter.IsUsed = false;
                myCharacter.Chars  = (char)charInt;
                //汉字的unicode编码范围是4e00-9fa5(19968至40869)
                //全/半角标点可以查看charInt输出
                switch (charInt)
                {
                case 8:
                    myCharacter.CharacterType = (int)CharacterType.BackSpace;
                    break;

                case 9:
                    myCharacter.CharacterType = (int)CharacterType.Tab;
                    break;

                case 13:
                    myCharacter.CharacterType = (int)CharacterType.Enter;
                    break;

                case 27:
                    myCharacter.CharacterType = (int)CharacterType.Esc;
                    break;

                default:
                    myCharacter.CharacterType = (int)CharacterType.Char;
                    break;
                }
                myCharacters.Add(myCharacter);
                break;
            }
            }
        }
Example #3
0
 /// <summary>
 /// Enable the IME
 /// </summary>
 public void enableIME()
 {
     IsEnabled = true;
     IMM.ImmAssociateContext(Handle, _context);
 }