Skip to content

Instantly share code, notes, and snippets.

@codler
Created June 14, 2011 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codler/1024805 to your computer and use it in GitHub Desktop.
Save codler/1024805 to your computer and use it in GitHub Desktop.
Screen capture
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
using System.Runtime.InteropServices;
// Made By Han Lin Yap 2011-03-03
public class screen_capture
{
static void Main(string[] args)
{
IntPtr hWnd = FindWindow(null, "TestHideApplication ");
if (hWnd != IntPtr.Zero)
{
//Hide the window
ShowWindow(hWnd, 0); // 0 = SW_HIDE
}
int screenWidth = Screen.GetBounds(new Point(0, 0)).Width;
int screenHeight = Screen.GetBounds(new Point(0, 0)).Height;
Bitmap bmpScreenShot = new Bitmap(screenWidth, screenHeight);
Graphics gfx = Graphics.FromImage((Image)bmpScreenShot);
gfx.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight));
bmpScreenShot.Save("test.png", ImageFormat.Png);
}
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment