Esempio n. 1
0
        /*  Will clean this up later doing something like this
         * enum  CaptureOptions : long
         * {
         *  PRF_CHECKVISIBLE= 0x00000001L,
         *  PRF_NONCLIENT	= 0x00000002L,
         *  PRF_CLIENT		= 0x00000004L,
         *  PRF_ERASEBKGND	= 0x00000008L,
         *  PRF_CHILDREN	= 0x00000010L,
         *  PRF_OWNED		= 0x00000020L
         * }
         */


        public static bool CaptureWindow(System.Windows.Forms.Control control,
                                         ref System.Drawing.Bitmap bitmap)
        {
            //This function captures the contents of a window or control

            Graphics g2 = Graphics.FromImage(bitmap);

            //PRF_CHILDREN // PRF_NONCLIENT
            int meint = (int)(PRF_CLIENT | PRF_ERASEBKGND); //| PRF_OWNED ); //  );

            System.IntPtr meptr = new System.IntPtr(meint);

            System.IntPtr hdc = g2.GetHdc();

            WIN32.SendMessage(control.Handle, WIN32.WM_PRINT, hdc, meptr);

            g2.ReleaseHdc(hdc);
            g2.Dispose();

            return(true);
        }
Esempio n. 2
0
        private Point findCaret()
        {
            Point  pointCaret  = new Point(0);
            int    i_char_loc  = this.SelectionStart;
            IntPtr pi_char_loc = new IntPtr(i_char_loc);

            int i_point = WIN32.SendMessage(this.Handle, WIN32.EM_POSFROMCHAR, pi_char_loc, IntPtr.Zero);

            pointCaret = new Point(i_point);

            if (i_char_loc == 0)
            {
                pointCaret = new Point(0);
            }
            else if (i_char_loc >= this.Text.Length)
            {
                pi_char_loc = new IntPtr(i_char_loc - 1);
                i_point     = WIN32.SendMessage(this.Handle, WIN32.EM_POSFROMCHAR, pi_char_loc, IntPtr.Zero);
                pointCaret  = new Point(i_point);

                Graphics g      = this.CreateGraphics();
                String   t1     = this.Text.Substring(this.Text.Length - 1, 1) + "X";
                SizeF    sizet1 = g.MeasureString(t1, this.Font);
                SizeF    sizex  = g.MeasureString("X", this.Font);
                g.Dispose();
                int xoffset = (int)(sizet1.Width - sizex.Width);
                pointCaret.X = pointCaret.X + xoffset;

                if (i_char_loc == this.Text.Length)
                {
                    String slast = this.Text.Substring(Text.Length - 1, 1);
                    if (slast == "\n")
                    {
                        pointCaret.X = 1;
                        pointCaret.Y = pointCaret.Y + myFontHeight;
                    }
                }
            }
            return(pointCaret);
        }