Click here to Skip to main content
15,843,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,
Can you please guide me the concepts/articles which would help me to write a program to take a screen shot/ Video of the desktop while a user is working or idle and save it to a folder. Can this happen. if so please help me.


1 solution


It's fairly easy to capture screenshots using the gdi32 api.
Look at this article by James Crowley[^]

public Image CaptureWindow(IntPtr handle)
    // get te hDC of the target window
    IntPtr hdcSrc = User32.GetWindowDC(handle);
    // get the size
    User32.RECT windowRect = new User32.RECT();
    User32.GetWindowRect(handle,ref windowRect);
    int width = windowRect.right - windowRect.left;
    int height = windowRect.bottom -;
    // create a device context we can copy to
    IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
    // create a bitmap we can copy it to,
    // using GetDeviceCaps to get the width/height
    IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc,width,height);
    // select the bitmap object
    IntPtr hOld = GDI32.SelectObject(hdcDest,hBitmap);
    // bitblt over
    // restore selection
    // clean up
    // get a .NET image object for it
    Image img = Image.FromHbitmap(hBitmap);
    // free up the Bitmap object
    return img;

If you want to capture video then you could have a look Microsoft Expression encoder.

here is a code sample showing video capture:

_screenCaptureJob = new ScreenCaptureJob();
int width = Convert.ToInt32(area.Width / 4) * 4;
int height = Convert.ToInt32(area.Height / 4) * 4;
Rectangle rect = new Rectangle(area.Location, new Size(width, height));
_screenCaptureJob.CaptureRectangle = rect;
_screenCaptureJob.ShowFlashingBoundary = true;
_screenCaptureJob.ScreenCaptureVideoProfile.FrameRate = 8;
_screenCaptureJob.ScreenCaptureVideoProfile.Quality = 75;
_screenCaptureJob.CaptureMouseCursor = true;
_screenCaptureJob.OutputScreenCaptureFileName = Path.ChangeExtension(Path.Combine(this.textBox1.Text, Path.GetRandomFileName()), ".wmv");
_screenCaptureJob.Duration = new TimeSpan(0, 0, Convert.ToInt32(textBoxVideoLength.Text));

These two code sample are in c#.

Share this answer
Sergey Alexandrovich Kryukov 28-May-11 13:27pm    
Very nice, a 5.
Valery Possoz 28-May-11 16:11pm    
Thanks :) Valery.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900