Add FrmScreenshooter
This commit is contained in:
26
VAR.Toolbox/Code/GDI32.cs
Normal file
26
VAR.Toolbox/Code/GDI32.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class GDI32
|
||||
{
|
||||
public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
|
||||
int nWidth, int nHeight, IntPtr hObjectSource,
|
||||
int nXSrc, int nYSrc, int dwRop);
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth,
|
||||
int nHeight);
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteDC(IntPtr hDC);
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteObject(IntPtr hObject);
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
||||
}
|
||||
}
|
||||
78
VAR.Toolbox/Code/Screenshooter.cs
Normal file
78
VAR.Toolbox/Code/Screenshooter.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class Screenshooter
|
||||
{
|
||||
|
||||
///// <summary>
|
||||
///// Creates an Image object containing a screen shot of the entire desktop
|
||||
///// </summary>
|
||||
///// <returns></returns>
|
||||
//public static Image CaptureScreen()
|
||||
//{
|
||||
// return CaptureWindow(User32.GetDesktopWindow());
|
||||
//}
|
||||
|
||||
public static Bitmap CaptureScreen()
|
||||
{
|
||||
// Determine the size of the "virtual screen", which includes all monitors.
|
||||
int screenLeft = SystemInformation.VirtualScreen.Left;
|
||||
int screenTop = SystemInformation.VirtualScreen.Top;
|
||||
int screenWidth = SystemInformation.VirtualScreen.Width;
|
||||
int screenHeight = SystemInformation.VirtualScreen.Height;
|
||||
|
||||
// Create a bitmap of the appropriate size to receive the screenshot.
|
||||
Bitmap bmp = new Bitmap(screenWidth, screenHeight);
|
||||
|
||||
// Draw the screenshot into our bitmap.
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an Image object containing a screen shot of a specific window
|
||||
/// </summary>
|
||||
/// <param name="handle">The handle to the window. (In windows forms, this is obtained by the Handle property)</param>
|
||||
/// <returns></returns>
|
||||
public static 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 - windowRect.top;
|
||||
// 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
|
||||
GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
|
||||
// restore selection
|
||||
GDI32.SelectObject(hdcDest, hOld);
|
||||
// clean up
|
||||
GDI32.DeleteDC(hdcDest);
|
||||
User32.ReleaseDC(handle, hdcSrc);
|
||||
|
||||
// get a .NET image object for it
|
||||
Image img = Image.FromHbitmap(hBitmap);
|
||||
// free up the Bitmap object
|
||||
GDI32.DeleteObject(hBitmap);
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -142,5 +142,23 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ReleaseCapture();
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT
|
||||
{
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
|
||||
}
|
||||
}
|
||||
79
VAR.Toolbox/UI/FrmScreenshooter.Designer.cs
generated
Normal file
79
VAR.Toolbox/UI/FrmScreenshooter.Designer.cs
generated
Normal file
@@ -0,0 +1,79 @@
|
||||
namespace VAR.Toolbox.UI
|
||||
{
|
||||
partial class FrmScreenshooter
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.btnScreenshoot = new System.Windows.Forms.Button();
|
||||
this.picViewer = new VAR.Toolbox.Controls.CtrImageViewer();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picViewer)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnScreenshoot
|
||||
//
|
||||
this.btnScreenshoot.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnScreenshoot.Location = new System.Drawing.Point(12, 390);
|
||||
this.btnScreenshoot.Name = "btnScreenshoot";
|
||||
this.btnScreenshoot.Size = new System.Drawing.Size(75, 23);
|
||||
this.btnScreenshoot.TabIndex = 1;
|
||||
this.btnScreenshoot.Text = "Screenshoot";
|
||||
this.btnScreenshoot.UseVisualStyleBackColor = true;
|
||||
this.btnScreenshoot.Click += new System.EventHandler(this.btnScreenshoot_Click);
|
||||
//
|
||||
// picViewer
|
||||
//
|
||||
this.picViewer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.picViewer.BackColor = System.Drawing.Color.Black;
|
||||
this.picViewer.ImageShow = null;
|
||||
this.picViewer.Location = new System.Drawing.Point(13, 13);
|
||||
this.picViewer.Name = "picViewer";
|
||||
this.picViewer.Size = new System.Drawing.Size(580, 371);
|
||||
this.picViewer.TabIndex = 0;
|
||||
this.picViewer.TabStop = false;
|
||||
//
|
||||
// FrmScreenshooter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(605, 425);
|
||||
this.Controls.Add(this.btnScreenshoot);
|
||||
this.Controls.Add(this.picViewer);
|
||||
this.Name = "FrmScreenshooter";
|
||||
this.Text = "FrmScreenshooter";
|
||||
((System.ComponentModel.ISupportInitialize)(this.picViewer)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private VAR.Toolbox.Controls.CtrImageViewer picViewer;
|
||||
private System.Windows.Forms.Button btnScreenshoot;
|
||||
}
|
||||
}
|
||||
19
VAR.Toolbox/UI/FrmScreenshooter.cs
Normal file
19
VAR.Toolbox/UI/FrmScreenshooter.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code;
|
||||
|
||||
namespace VAR.Toolbox.UI
|
||||
{
|
||||
public partial class FrmScreenshooter : Form
|
||||
{
|
||||
public FrmScreenshooter()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void btnScreenshoot_Click(object sender, EventArgs e)
|
||||
{
|
||||
picViewer.ImageShow = Screenshooter.CaptureScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
71
VAR.Toolbox/UI/FrmToolbox.Designer.cs
generated
71
VAR.Toolbox/UI/FrmToolbox.Designer.cs
generated
@@ -40,13 +40,15 @@
|
||||
this.btnExit = new System.Windows.Forms.Button();
|
||||
this.btnTestSoapService = new System.Windows.Forms.Button();
|
||||
this.btnTestRestService = new System.Windows.Forms.Button();
|
||||
this.btnScreenshooter = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btnBase64
|
||||
//
|
||||
this.btnBase64.Location = new System.Drawing.Point(9, 52);
|
||||
this.btnBase64.Location = new System.Drawing.Point(14, 80);
|
||||
this.btnBase64.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnBase64.Name = "btnBase64";
|
||||
this.btnBase64.Size = new System.Drawing.Size(165, 34);
|
||||
this.btnBase64.Size = new System.Drawing.Size(248, 52);
|
||||
this.btnBase64.TabIndex = 0;
|
||||
this.btnBase64.Text = "Base64";
|
||||
this.btnBase64.UseVisualStyleBackColor = true;
|
||||
@@ -54,9 +56,10 @@
|
||||
//
|
||||
// btnProxyCmd
|
||||
//
|
||||
this.btnProxyCmd.Location = new System.Drawing.Point(9, 92);
|
||||
this.btnProxyCmd.Location = new System.Drawing.Point(14, 142);
|
||||
this.btnProxyCmd.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnProxyCmd.Name = "btnProxyCmd";
|
||||
this.btnProxyCmd.Size = new System.Drawing.Size(165, 36);
|
||||
this.btnProxyCmd.Size = new System.Drawing.Size(248, 55);
|
||||
this.btnProxyCmd.TabIndex = 1;
|
||||
this.btnProxyCmd.Text = "ProxyCmd";
|
||||
this.btnProxyCmd.UseVisualStyleBackColor = true;
|
||||
@@ -64,9 +67,10 @@
|
||||
//
|
||||
// btnWebcam
|
||||
//
|
||||
this.btnWebcam.Location = new System.Drawing.Point(9, 135);
|
||||
this.btnWebcam.Location = new System.Drawing.Point(14, 208);
|
||||
this.btnWebcam.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnWebcam.Name = "btnWebcam";
|
||||
this.btnWebcam.Size = new System.Drawing.Size(165, 36);
|
||||
this.btnWebcam.Size = new System.Drawing.Size(248, 55);
|
||||
this.btnWebcam.TabIndex = 2;
|
||||
this.btnWebcam.Text = "Webcam";
|
||||
this.btnWebcam.UseVisualStyleBackColor = true;
|
||||
@@ -74,10 +78,9 @@
|
||||
//
|
||||
// btnTunnelTCP
|
||||
//
|
||||
this.btnTunnelTCP.Location = new System.Drawing.Point(9, 175);
|
||||
this.btnTunnelTCP.Margin = new System.Windows.Forms.Padding(2);
|
||||
this.btnTunnelTCP.Location = new System.Drawing.Point(14, 269);
|
||||
this.btnTunnelTCP.Name = "btnTunnelTCP";
|
||||
this.btnTunnelTCP.Size = new System.Drawing.Size(165, 36);
|
||||
this.btnTunnelTCP.Size = new System.Drawing.Size(248, 55);
|
||||
this.btnTunnelTCP.TabIndex = 5;
|
||||
this.btnTunnelTCP.Text = "TunnelTCP";
|
||||
this.btnTunnelTCP.UseVisualStyleBackColor = true;
|
||||
@@ -88,28 +91,27 @@
|
||||
this.lblToolbox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.lblToolbox.Font = new System.Drawing.Font("Arial Narrow", 28F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lblToolbox.Location = new System.Drawing.Point(9, 9);
|
||||
this.lblToolbox.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
|
||||
this.lblToolbox.Location = new System.Drawing.Point(14, 14);
|
||||
this.lblToolbox.Name = "lblToolbox";
|
||||
this.lblToolbox.Size = new System.Drawing.Size(336, 40);
|
||||
this.lblToolbox.Size = new System.Drawing.Size(504, 62);
|
||||
this.lblToolbox.TabIndex = 6;
|
||||
this.lblToolbox.Text = "Toolbox";
|
||||
this.lblToolbox.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// pnlSuspension1
|
||||
//
|
||||
this.pnlSuspension1.Location = new System.Drawing.Point(180, 241);
|
||||
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(1);
|
||||
this.pnlSuspension1.Location = new System.Drawing.Point(270, 371);
|
||||
this.pnlSuspension1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.pnlSuspension1.Name = "pnlSuspension1";
|
||||
this.pnlSuspension1.Size = new System.Drawing.Size(165, 114);
|
||||
this.pnlSuspension1.Size = new System.Drawing.Size(248, 175);
|
||||
this.pnlSuspension1.TabIndex = 4;
|
||||
//
|
||||
// pnlCover1
|
||||
//
|
||||
this.pnlCover1.Location = new System.Drawing.Point(12, 241);
|
||||
this.pnlCover1.Margin = new System.Windows.Forms.Padding(1);
|
||||
this.pnlCover1.Location = new System.Drawing.Point(18, 371);
|
||||
this.pnlCover1.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.pnlCover1.Name = "pnlCover1";
|
||||
this.pnlCover1.Size = new System.Drawing.Size(162, 114);
|
||||
this.pnlCover1.Size = new System.Drawing.Size(243, 175);
|
||||
this.pnlCover1.TabIndex = 3;
|
||||
//
|
||||
// niTray
|
||||
@@ -120,9 +122,10 @@
|
||||
//
|
||||
// btnExit
|
||||
//
|
||||
this.btnExit.Location = new System.Drawing.Point(12, 359);
|
||||
this.btnExit.Location = new System.Drawing.Point(18, 552);
|
||||
this.btnExit.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnExit.Name = "btnExit";
|
||||
this.btnExit.Size = new System.Drawing.Size(333, 29);
|
||||
this.btnExit.Size = new System.Drawing.Size(500, 45);
|
||||
this.btnExit.TabIndex = 7;
|
||||
this.btnExit.Text = "Exit";
|
||||
this.btnExit.UseVisualStyleBackColor = true;
|
||||
@@ -130,9 +133,10 @@
|
||||
//
|
||||
// btnTestSoapService
|
||||
//
|
||||
this.btnTestSoapService.Location = new System.Drawing.Point(180, 52);
|
||||
this.btnTestSoapService.Location = new System.Drawing.Point(270, 80);
|
||||
this.btnTestSoapService.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnTestSoapService.Name = "btnTestSoapService";
|
||||
this.btnTestSoapService.Size = new System.Drawing.Size(165, 34);
|
||||
this.btnTestSoapService.Size = new System.Drawing.Size(248, 52);
|
||||
this.btnTestSoapService.TabIndex = 8;
|
||||
this.btnTestSoapService.Text = "TestSoapService";
|
||||
this.btnTestSoapService.UseVisualStyleBackColor = true;
|
||||
@@ -140,19 +144,32 @@
|
||||
//
|
||||
// btnTestRestService
|
||||
//
|
||||
this.btnTestRestService.Location = new System.Drawing.Point(180, 92);
|
||||
this.btnTestRestService.Location = new System.Drawing.Point(270, 142);
|
||||
this.btnTestRestService.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnTestRestService.Name = "btnTestRestService";
|
||||
this.btnTestRestService.Size = new System.Drawing.Size(165, 36);
|
||||
this.btnTestRestService.Size = new System.Drawing.Size(248, 55);
|
||||
this.btnTestRestService.TabIndex = 9;
|
||||
this.btnTestRestService.Text = "TestRestService";
|
||||
this.btnTestRestService.UseVisualStyleBackColor = true;
|
||||
this.btnTestRestService.Click += new System.EventHandler(this.btnTestRestService_Click);
|
||||
//
|
||||
// btnScreenshooter
|
||||
//
|
||||
this.btnScreenshooter.Location = new System.Drawing.Point(270, 208);
|
||||
this.btnScreenshooter.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnScreenshooter.Name = "btnScreenshooter";
|
||||
this.btnScreenshooter.Size = new System.Drawing.Size(248, 55);
|
||||
this.btnScreenshooter.TabIndex = 10;
|
||||
this.btnScreenshooter.Text = "Screenshooter";
|
||||
this.btnScreenshooter.UseVisualStyleBackColor = true;
|
||||
this.btnScreenshooter.Click += new System.EventHandler(this.btnScreenshooter_Click);
|
||||
//
|
||||
// FrmToolbox
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(352, 400);
|
||||
this.ClientSize = new System.Drawing.Size(528, 615);
|
||||
this.Controls.Add(this.btnScreenshooter);
|
||||
this.Controls.Add(this.btnTestRestService);
|
||||
this.Controls.Add(this.btnTestSoapService);
|
||||
this.Controls.Add(this.btnExit);
|
||||
@@ -164,6 +181,7 @@
|
||||
this.Controls.Add(this.btnProxyCmd);
|
||||
this.Controls.Add(this.btnBase64);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "FrmToolbox";
|
||||
this.Text = "Toolbox";
|
||||
@@ -187,6 +205,7 @@
|
||||
private System.Windows.Forms.Button btnExit;
|
||||
private System.Windows.Forms.Button btnTestSoapService;
|
||||
private System.Windows.Forms.Button btnTestRestService;
|
||||
private System.Windows.Forms.Button btnScreenshooter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -105,6 +105,11 @@ namespace VAR.Toolbox.UI
|
||||
CreateWindow(typeof(FrmTestRestService));
|
||||
}
|
||||
|
||||
private void btnScreenshooter_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateWindow(typeof(FrmScreenshooter));
|
||||
}
|
||||
|
||||
#endregion UI events
|
||||
|
||||
#region Window handling
|
||||
|
||||
@@ -83,8 +83,10 @@
|
||||
<Compile Include="Code\DirectShow\Tools.cs" />
|
||||
<Compile Include="Code\DirectShow\Uuids.cs" />
|
||||
<Compile Include="Code\DirectShow\Win32.cs" />
|
||||
<Compile Include="Code\GDI32.cs" />
|
||||
<Compile Include="Code\Logger.cs" />
|
||||
<Compile Include="Code\Mouse.cs" />
|
||||
<Compile Include="Code\Screenshooter.cs" />
|
||||
<Compile Include="Code\User32.cs" />
|
||||
<Compile Include="Code\Webcam.cs" />
|
||||
<Compile Include="Code\Win32API.cs" />
|
||||
@@ -106,6 +108,12 @@
|
||||
<Compile Include="UI\FrmProxyCmd.Designer.cs">
|
||||
<DependentUpon>FrmProxyCmd.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\FrmScreenshooter.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="UI\FrmScreenshooter.Designer.cs">
|
||||
<DependentUpon>FrmScreenshooter.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="UI\FrmTestRestService.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
Reference in New Issue
Block a user