dbones notes
its a geek thing

Taking a screen shot showing the mouse posistion

January 30, 2008 23:54 by Dave

Here is some code i have written to take a screen shot of the primary monitor and show an icon where the mouse is located.

The function first takes a screen shot then goes onto to draw an icon at the same posistion where the mouse is located.

private Bitmap GetScreenShot()
        {
            //here is the code to capture the screen
            System.Drawing.Size rec = Screen.PrimaryScreen.Bounds.Size;
            Bitmap pic = new Bitmap(rec.Width,
                rec.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(pic);
            g.CopyFromScreen(0, 0, 0, 0, new Size(rec.Width, rec.Height));

            //Draw the icon < after the screen has been
            //captured, add a icon to the bitmap
            Point cp = new Point();
            User32.GetCursorPos(out cp);
            g.DrawIcon(SystemIcons.Hand, cp.X, cp.Y);
           
            //return the picture, and display it in a control
            return pic;

        }

To get the posistion of the mouse can be done a couple ways, in this code i used the pinvoke way calling the User32 functions

static class User32
    {

        [DllImport("user32.dll")]
        public static extern IntPtr GetCursor();

        [DllImport("user32.dll")]
        public static extern bool GetCursorPos(out Point lpPoint);

    }

Here is an example look at the caution icon, that is where the mouse was.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Tags:
Categories: dotNet
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts