コード例 #1
0
        private int GetCharIndexFromPos(int x, int y)
        {
            var p = new User32.POINTL {
                X = x, Y = y
            };
            int    rawSize = Marshal.SizeOf(typeof(User32.POINTL));
            IntPtr lParam  = Marshal.AllocHGlobal(rawSize);

            Marshal.StructureToPtr(p, lParam, false);
            int r = User32.SendMessage(this.Handle, (int)User32.Msgs.EM_CHARFROMPOS, 0, lParam);

            Marshal.FreeHGlobal(lParam);
            return(r);
        }
コード例 #2
0
        private Point GetPosFromCharIndex(int ix)
        {
            int    rawSize = Marshal.SizeOf(typeof(User32.POINTL));
            IntPtr wParam  = Marshal.AllocHGlobal(rawSize);
            int    r       = User32.SendMessage(this.Handle, (int)User32.Msgs.EM_POSFROMCHAR, (int)wParam, ix);

            User32.POINTL p1 = (User32.POINTL)Marshal.PtrToStructure(wParam, typeof(User32.POINTL));

            Marshal.FreeHGlobal(wParam);
            var p = new Point {
                X = p1.X, Y = p1.Y
            };

            return(p);
        }