c# wince 下获取当前输入法状态2

19 篇文章 0 订阅

我的博客中有一篇介绍如何获取当前输入状态,这里主要介绍通过RegisterWindowMessage("Keyboard_ICO")注册一个消息ID

代码经过测试是OK的

注册类:

class CustomMessageWindow : Microsoft.WindowsCE.Forms.MessageWindow
    {
        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]
        private static extern uint RegisterWindowMessage(string lpString);    
        public delegate void DelTextBoxMsg(string msg);
        public event DelTextBoxMsg Msg;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref Microsoft.WindowsCE.Forms.Message m)
        {
            try
            {
                //MessageBox.Show("消息句柄:" + m.HWnd.ToString() + "  id:" + m.Msg + "   wparam:" + m.WParam + "  LParam:" + m.LParam);
                if (m.Msg == RegisterWindowMessage("Keyboard_ICO"))
                {
                    switch (m.LParam.ToInt32())
                    {
                        case 40:  //大写                          
                            Msg("40");
                            break;
                        case 41:  //小写                           
                            Msg("41");
                            break;
                        case 42:  //数字                           
                            Msg("42");
                            break;
                        case 43:  //字符                           
                            Msg("43");
                            break;                         
                       default:
                            break;
                    }
                }
            }
            catch
            {            }
        }
    }

监控界面做的事情:

CustomMessageWindow customMessageWindow = new CustomMessageWindow();//实例化    

public MainForm()
        {
            InitializeComponent();
            customMessageWindow.Msg += new CustomMessageWindow.DelTextBoxMsg(customMessageWindow_Msg);//注册
        }


void customMessageWindow_Msg(string msg)
        {
            if (msg == "40")
                label1.Text = "A";
            else if (msg == "41")
                label1.Text = "a";
            else if (msg == "42")
                label1.Text = "9";
            else if (msg == "43")
                label1.Text = "#";
            else
                label1.Text = "a";

        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值