如何将软件输入面板(键盘)移动到Windows移动屏幕的底部?

时间:2011-08-22 21:09:31

标签: .net windows-mobile compact-framework pinvoke

我试图将键盘移动到屏幕底部以隐藏它在Windows Mobile 5/6上默认显示的35px菜单栏。我所看到的关于修改菜单栏的所有示例都涉及隐藏按钮" MS_SIPBUTTON"。我的问题的两个部分是:

如何在屏幕上将键盘向下移动35个像素?

而且," MS_SIPBUTTON"定义

1 个答案:

答案 0 :(得分:1)

第一部分:

我可以集中移动键盘的最佳方式是从pinvoke.net引用的所有Windows API调用

首先是一堆DllImport语句:

        [DllImport("coredll.dll", SetLastError = true)]
        private static extern IntPtr FindWindow(string caption, string className);

        [DllImport("coredll.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);

        [DllImport("coredll.dll")]
        internal static extern void MoveWindow(IntPtr hwnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);

        [DllImport("coredll.dll", SetLastError = true)]
        extern static int SipShowIM(int dwFlag);

接下来是一些常量和变量:

        Rectangle sipbutton;
        Rectangle keyboardBackground;
        Rectangle keyboard;

        private const int SW_HIDE = 0;
        private const int SW_SHOW = 1;
        private const int GW_CHILD = 5;
        private const int SIPF_ON = 1;
        private const int SIPF_OFF = 0;

用于显示和隐藏页面底部显示的SIP按钮的功能。它们在我的构造函数和析构函数中被调用

            public void HideSip()
            {
                IntPtr hTaskBarWindow = FindWindow("MS_SIPBUTTON", null);
                if (hTaskBarWindow != IntPtr.Zero)
                {
                    RECT rct;

                    if (!GetWindowRect(hTaskBarWindow, out rct))
                    {
                        MessageBox.Show("ERROR");
                        return;
                    }

                    Rectangle myRect = new Rectangle();

                    myRect.X = (int)rct.Left;
                    myRect.Y = (int)rct.Top;
                    myRect.Width = (int)(rct.Right - rct.Left + 1);
                    myRect.Height = (int)(rct.Bottom - rct.Top + 1);

                    //save previous state
                    sipbutton = myRect;

                    MoveWindow(hTaskBarWindow, myRect.X, myRect.Y + 1000, myRect.Width, myRect.Height, true);
                    //MoveWindow(hTaskBarWindow, 100, 100, 100, 100, true);
                }
            }

            public void RestoreSip()
            {
                IntPtr hTaskBarWindow = FindWindow("MS_SIPBUTTON", null);
                if (hTaskBarWindow != IntPtr.Zero && sipbutton.Height > 0 && sipbutton.Width > 0)
                {
                    MoveWindow(hTaskBarWindow, sipbutton.X, sipbutton.Y, sipbutton.Width, sipbutton.Height, true);
                }
            }

我们需要将键盘向下移动到屏幕底部:

public void MoveKeyboardDown(int pixelsDown)
        {

            IntPtr hSipWindow = FindWindow("SipWndClass",null);
            if (hSipWindow != IntPtr.Zero)
            {
                RECT rct;

                if (!GetWindowRect(hSipWindow, out rct))
                {
                    MessageBox.Show("ERROR");
                    return;
                }

                Rectangle myRect = new Rectangle();

                myRect.X = (int)rct.Left;
                myRect.Y = (int)rct.Top;
                myRect.Width = (int)(rct.Right - rct.Left + 1);
                myRect.Height = (int)(rct.Bottom - rct.Top + 1);

                //save previous state
                keyboard = myRect;

                MoveWindow(hSipWindow, myRect.X, myRect.Y + pixelsDown, myRect.Width, myRect.Height, true);

            }

            IntPtr hSipWindow2 = FindWindow("SipBackDropWndClass",null);
            if (hSipWindow2 != IntPtr.Zero)
            {
                RECT rct;

                if (!GetWindowRect(hSipWindow2, out rct))
                {
                    MessageBox.Show("ERROR");
                    return;
                }

                Rectangle myRect = new Rectangle();

                myRect.X = (int)rct.Left;
                myRect.Y = (int)rct.Top;
                myRect.Width = (int)(rct.Right - rct.Left + 1);
                myRect.Height = (int)(rct.Bottom - rct.Top + 1);

                //save previous state
                keyboardBackground = myRect;

                MoveWindow(hSipWindow2, myRect.X, myRect.Y + pixelsDown, myRect.Width, myRect.Height, true);

            }


            arPages[iCurrentPage].Invalidate();
        }

        public void RestoreKeyboard()
        {

            IntPtr hSipWindow = FindWindow("SipWndClass", null);
            if (hSipWindow != IntPtr.Zero && keyboard.Height > 0 && keyboard.Width > 0)
            {
                MoveWindow(hSipWindow, keyboard.X, keyboard.Y, keyboard.Width, keyboard.Height, true);
            }

            IntPtr hSipWindow2 = FindWindow("SipBackDropWndClass", null);
            if (hSipWindow2 != IntPtr.Zero && keyboardBackground.Height > 0 && keyboardBackground.Width > 0)
            {
                MoveWindow(hSipWindow2, keyboardBackground.X, keyboardBackground.Y, keyboardBackground.Width, keyboardBackground.Height, true);
            }

        }

当您想要显示键盘时,请执行以下操作:

    SipShowIM(SIPF_ON);
    MoveKeyboardDown(25);

如果你想隐藏它,请执行以下操作:

    SipShowIM(SIPF_OFF);
    RestoreKeyboard();

第二部分:

我能够使用CE远程工具/ Windows CE远程间谍发现上面引用的窗口名称。可执行文件是“ccspy.exe”