输入法弹窗位置

        [DllImport"imm32.dll")]
        public static extern bool ImmGetOpenStatus (IntPtr hIMC);
        [ DllImport("imm32.dll" )]
        public static extern IntPtr ImmGetContext (IntPtr hWnd);
        [ DllImport("imm32.dll" )]
        public static extern int ImmReleaseContext (IntPtr hWndIntPtr hIMC);
        [ DllImport("imm32.dll" )]
        public static extern bool ImmSetCompositionWindow (IntPtr hIMCref   COMPOSITIONFORM lpCompForm);
 
        [ StructLayout(LayoutKind .Sequential)]
        public struct RECT
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
        [ StructLayout(LayoutKind .Sequential)]
        public struct POINTAPI
        {
            public int X;
            public int Y;
        }
        [ StructLayout(LayoutKind .Sequential)]
        public struct COMPOSITIONFORM
        {
            public uint dwStyle;
            public POINTAPI ptCurrentPos;
            public RECT rcArea;
        }
 
        const int EM_GETSEL = 0xB0;
        const int EM_LINEFROMCHAR = 0xC9;
        const int EM_LINEINDEX = 0xBB;
        [ DllImport("user32.dll" EntryPoint "SendMessage")]
        public static extern int SendMessage (
            int hwnd ,
            int wMsg ,
            int wParam ,
            ref int lParam
        );
        private Point GetCursorPosint TextHwnd )
        {
            int = 0, = 0, = 0;
            int lParam = 0, wParam = 0;
            SendMessage (TextHwndEM_GETSELwParam ref lParam);
            / 65536;
            int lineNo SendMessageTextHwndEM_LINEFROMCHAR jref lParam ) + 1;
            SendMessage (TextHwndEM_LINEINDEX, -1, ref lParam);
            int colNo + 1;
            Point ret new Point(lineNo colNo);
            return ret ;
        }  
 
 
        void textBox_KeyDown(object senderKeyEventArgs )
        {
            IntPtr it = ((SystemWindows.Interop .HwndSourcePresentationSource.FromVisual (rBox)). Handle;
            IntPtr hImc ImmGetContextit);
            if (ImmGetOpenStatus (hImc))
            {
                COMPOSITIONFORM cf new COMPOSITIONFORM();
                cf.dwStyle = 2;
 
                //Point p = GetCursorPos(it.ToInt32());
                //Point p1 = this.PointToScreen(p);
                Point p2 thisTranslatePoint(new Point(0, 0), CVisualTreeHelper.GetParent <Window>( this));
                cf.ptCurrentPos .= ( int)p2 .X;
                cf.ptCurrentPos .= ( int)p2 .+ 300;
                bool setcom ImmSetCompositionWindowhImcref cf);
            }
            ImmReleaseContext(hImc it);
        }
 
 
 
资料
 
msdn: https://msdn.microsoft.com/en-us/library/dd318653(v=vs.85).aspx
 
http://msdn.microsoft.com/en-us/library/dd317764(v=VS.85).aspx

CFS_DEFAULT Move the composition window to the default position. The IME window can display the composition window outside the client area, such as in a floating window. 
CFS_FORCE_POSITION Display the upper left corner of the composition window at exactly the position specified by ptCurrentPos. The coordinates are relative to the upper left corner of the window containing the composition window and are not subject to adjustment by the IME. 
CFS_POINT Display the upper left corner of the composition window at the position specified by ptCurrentPos. The coordinates are relative to the upper left corner of the window containing the composition window and are subject to adjustment by the IME. 
CFS_RECT Display the composition window at the position specified by rcArea. The coordinates are relative to the upper left of the window containing the composition window. 

http://dev.firnow.com/course/4_webprogram/asp.net/netjs/2008215/99962_35.html

Public Const CFS_DEFAULT = &H0
Public Const CFS_RECT = &H1
Public Const CFS_POINT = &H2
Public Const CFS_SCREEN = &H4
Public Const CFS_FORCE_POSITION = &H20
Public Const CFS_CANDIDATEPOS = &H40
Public Const CFS_EXCLUDE = &H80
posted @ 2018-03-31 15:53  死鱼眼の猫  阅读(376)  评论(0编辑  收藏  举报