A widget that captures computer screens Program
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. Windows. forms;
Using System. drawing;
Using System. Drawing. imaging;
Namespace Deskregistrar
{
Class Program
{
// Declare an API Function
[System. runtime. interopservices. dllimportattribute ( " Gdi32.dll " )]
Private Static Extern Bool Bitblt (
Intptr hdcdest, // Handle of the Target DC
Int Nxdest,
Int Nydest,
Int Nwidth,
Int Nheight,
Intptr hdcsrc, // Source DC handle
Int Nxsrc,
Int Nysrc,
System. int32 dwdrop // Grating processing value
);
[System. runtime. interopservices. dllimportattribute ( " Gdi32.dll " )]
Private Static Extern Intptr createdc (
String Lpszdriver, // Driver name
String Lpszdevice, // Device Name
String Lpszoutput, // Useless. You can set a "null"
Intptr lpinitdata // Any printer data
);
Static VoidMain (String[] ARGs)
{
System. Threading. Timer = New System. Threading. Timer ( Delegate (Object O)
{
Intptr DC1 = Createdc ( " Display " , Null , Null , (Intptr) Null );
// Create a DC for the monitor
Graphics G1 = Graphics. fromhdc (DC1 );
// Creates a new graphics object by the handle of a specified device.
Image myimage = New Bitmap (screen. primaryscreen. bounds. Width, screen. primaryscreen. bounds. Height, G1 );
// Create a bitmap object of the same size as the screen size
Graphics G2 = Graphics. fromimage (myimage );
// Obtain the screen handle
Intptr DC3 = G1.gethdc ();
// Obtain the bitmap handle.
Intptr DC2 = G2.gethdc ();
// Capturing the current screen in the image object
Bitblt (DC2, 0 , 0 , Screen. primaryscreen. bounds. Width, screen. primaryscreen. bounds. Height, DC3, 0 , 0 , 13369376 );
// Copy the current screen to the image
G1.releasehdc (DC3 );
// Release screen handle
G2.releasehdc (DC2 );
// Release bitmap handle
Myimage. Save (appdomain. currentdomain. basedirectory + " \\ " + Datetime. Now. tostring ( " Yyyymmddhhmmss " ) + " . Jpg " , Imageformat. JPEG );
// MessageBox. Show ("the current screen has been saved to the C: \ mydomain.jpg file! ");
}, Null , 0 , 3000 );
console. Read ();
}< BR >}