Created
June 14, 2011 12:30
-
-
Save codler/1024805 to your computer and use it in GitHub Desktop.
Screen capture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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