当前位置: 代码迷 >> Windows Mobile >> 关于C#实现截获输入法小键盘开启关闭的有关问题
  详细解决方案

关于C#实现截获输入法小键盘开启关闭的有关问题

热度:168   发布时间:2016-04-25 08:02:12.0
关于C#实现截获输入法小键盘开启关闭的问题
Windows Mobile中有一个小键盘的那个东西,会在任务栏上显示,点一下那个图标,会弹出小键盘,我想拦截这个小键盘的弹出,监视他的各种信息,我按照常规的方式,首先找到MS_SIPBUTTON这个窗口,然后试用SetWindowLong来替换他的窗口过程,以达到来监视WM_SETTINGCHANGE这个消息,来即时的监视键盘开启与关闭的状态。但是比较奇怪的时候,窗口过程勾取了之后,整个程序瘫痪了。这是啥子原因。希望专家帮忙帮忙!代码如下!
C# code
public sealed class DxKeyBoardOper    {        private static IntPtr KeyBoardWnd = IntPtr.Zero;        private static bool isInited = false;        private static bool IsWndHooked = false;        private static bool CanPopMenu = true;        private static IntPtr oldWndProc;//保存原窗口过程        public static bool initOperate()        {            //先找到键盘按钮句柄            KeyBoardWnd = DxNativeWindowsApi.FindWindow("MS_SIPBUTTON", "MS_SIPBUTTON");            if (KeyBoardWnd != IntPtr.Zero)            {                //替换窗口过程                                isInited = true;                return true;            }            return false;        }        public static void EndKeyBoardOper()        {            //关闭所有的            UnHookWndProc();            if (isInited)            {                isInited = false;                KeyBoardWnd = IntPtr.Zero;            };                    }        public static void HookWndProc()        {            if (!isInited)            {                initOperate();                if (isInited && !IsWndHooked)                {                     //DxNativeWindowsApi.SetWindowLong(KeyBoardWnd, DxWin32Consts.GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate());                    oldWndProc = (IntPtr)DxNativeWindowsApi.GetWindowLong(KeyBoardWnd, DxWin32Consts.GWL_WNDPROC);                     DxNativeWindowsApi.SetWindowLong(KeyBoardWnd, DxWin32Consts.GWL_WNDPROC, new DxWindowProcHook.WndProc(WindowProc));                    IsWndHooked = true;                }            }        }        public static void UnHookWndProc()        {            if (IsWndHooked)            {                IsWndHooked = false;                DxNativeWindowsApi.SetWindowLong(KeyBoardWnd, DxWin32Consts.GWL_WNDPROC, oldWndProc);            }        }        public static bool CancleKeyMenuPopUp        {            get            {                return CanPopMenu;            }            set            {                CanPopMenu = value;                HookWndProc();            }        }        private static int WindowProc(IntPtr hwnd, uint msg, uint wParam, int lParam)        {            return DxNativeWindowsApi.CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam);                switch(msg)            {                case DxMessages.WM_SETTINGCHANGE:                    if (wParam == DxWin32Consts.SPI_SETSIPINFO)                    {                        //设置显示软键盘                        DxNativeApiStructs.SIPINFO sipInfo = new DxNativeApiStructs.SIPINFO();                        sipInfo.cbSize = Marshal.SizeOf(typeof(DxNativeApiStructs.SIPINFO));                        DxNativeWindowsApi.SipGetInfo(ref sipInfo);                        if ((sipInfo.fdwFlags & (int)WindowsEnum.SIPStatus.SIPF_ON) == (int)WindowsEnum.SIPStatus.SIPF_ON)                        {                            //打开软键盘                        }                        else                        {                            //关闭软键盘                        }                    }                    break;                case DxMessages.WM_INITMENUPOPUP:                    IntPtr menuhand = (IntPtr)wParam;                    DxNativeWindowsApi.DestroyMenu(menuhand);                    break;            }                                                  }    }


------解决方案--------------------
哈哈。。。支持下啊~不错
------解决方案--------------------
探讨
  相关解决方案