From 581ef945efde9eea737dd4b1edad86aa0edc61b8 Mon Sep 17 00:00:00 2001 From: VPS Date: Fri, 11 Mar 2022 15:49:28 -0500 Subject: [PATCH] Add Screenshot Helper SRC --- rccscreenshot/rccscreenshot.sln | 25 ++++ rccscreenshot/rccscreenshot/App.config | 6 + rccscreenshot/rccscreenshot/Program.cs | 46 ++++++ .../rccscreenshot/Properties/AssemblyInfo.cs | 36 +++++ rccscreenshot/rccscreenshot/RECT.cs | 135 ++++++++++++++++++ .../rccscreenshot/rccscreenshot.csproj | 55 +++++++ 6 files changed, 303 insertions(+) create mode 100644 rccscreenshot/rccscreenshot.sln create mode 100644 rccscreenshot/rccscreenshot/App.config create mode 100644 rccscreenshot/rccscreenshot/Program.cs create mode 100644 rccscreenshot/rccscreenshot/Properties/AssemblyInfo.cs create mode 100644 rccscreenshot/rccscreenshot/RECT.cs create mode 100644 rccscreenshot/rccscreenshot/rccscreenshot.csproj diff --git a/rccscreenshot/rccscreenshot.sln b/rccscreenshot/rccscreenshot.sln new file mode 100644 index 0000000..a2b1419 --- /dev/null +++ b/rccscreenshot/rccscreenshot.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.329 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "rccscreenshot", "rccscreenshot\rccscreenshot.csproj", "{D35FDD7F-58B7-42ED-A16E-A793DA507783}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D35FDD7F-58B7-42ED-A16E-A793DA507783}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D35FDD7F-58B7-42ED-A16E-A793DA507783}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D35FDD7F-58B7-42ED-A16E-A793DA507783}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D35FDD7F-58B7-42ED-A16E-A793DA507783}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {63870D8E-8BD6-45A6-AC5D-9962669BCDA3} + EndGlobalSection +EndGlobal diff --git a/rccscreenshot/rccscreenshot/App.config b/rccscreenshot/rccscreenshot/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/rccscreenshot/rccscreenshot/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/rccscreenshot/rccscreenshot/Program.cs b/rccscreenshot/rccscreenshot/Program.cs new file mode 100644 index 0000000..117901d --- /dev/null +++ b/rccscreenshot/rccscreenshot/Program.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace rccscreenshot +{ + class Program + { + [DllImport("user32.dll")] + public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect); + [DllImport("user32.dll")] + public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags); + + static void Main(string[] args) + { + Process[] proc = Process.GetProcessesByName("RCCServiceSoap"); + if (proc.Length == 0) return; + + Bitmap image = PrintWindow(proc[0].MainWindowHandle); + image.Save("screenshot.png"); + } + + public static Bitmap PrintWindow(IntPtr hwnd) + { + RECT rc; + GetWindowRect(hwnd, out rc); + + Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb); + Graphics gfxBmp = Graphics.FromImage(bmp); + IntPtr hdcBitmap = gfxBmp.GetHdc(); + + PrintWindow(hwnd, hdcBitmap, 0); + + gfxBmp.ReleaseHdc(hdcBitmap); + gfxBmp.Dispose(); + + return bmp; + } + } +} diff --git a/rccscreenshot/rccscreenshot/Properties/AssemblyInfo.cs b/rccscreenshot/rccscreenshot/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1e1f60b --- /dev/null +++ b/rccscreenshot/rccscreenshot/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("rccscreenshot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("rccscreenshot")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d35fdd7f-58b7-42ed-a16e-a793da507783")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/rccscreenshot/rccscreenshot/RECT.cs b/rccscreenshot/rccscreenshot/RECT.cs new file mode 100644 index 0000000..b68b605 --- /dev/null +++ b/rccscreenshot/rccscreenshot/RECT.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace rccscreenshot +{ + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + private int _Left; + private int _Top; + private int _Right; + private int _Bottom; + + public RECT(RECT Rectangle) : this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom) + { + } + public RECT(int Left, int Top, int Right, int Bottom) + { + _Left = Left; + _Top = Top; + _Right = Right; + _Bottom = Bottom; + } + + public int X + { + get { return _Left; } + set { _Left = value; } + } + public int Y + { + get { return _Top; } + set { _Top = value; } + } + public int Left + { + get { return _Left; } + set { _Left = value; } + } + public int Top + { + get { return _Top; } + set { _Top = value; } + } + public int Right + { + get { return _Right; } + set { _Right = value; } + } + public int Bottom + { + get { return _Bottom; } + set { _Bottom = value; } + } + public int Height + { + get { return _Bottom - _Top; } + set { _Bottom = value + _Top; } + } + public int Width + { + get { return _Right - _Left; } + set { _Right = value + _Left; } + } + public Point Location + { + get { return new Point(Left, Top); } + set + { + _Left = value.X; + _Top = value.Y; + } + } + public Size Size + { + get { return new Size(Width, Height); } + set + { + _Right = value.Width + _Left; + _Bottom = value.Height + _Top; + } + } + + public static implicit operator Rectangle(RECT Rectangle) + { + return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height); + } + public static implicit operator RECT(Rectangle Rectangle) + { + return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom); + } + public static bool operator ==(RECT Rectangle1, RECT Rectangle2) + { + return Rectangle1.Equals(Rectangle2); + } + public static bool operator !=(RECT Rectangle1, RECT Rectangle2) + { + return !Rectangle1.Equals(Rectangle2); + } + + public override string ToString() + { + return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}"; + } + + public override int GetHashCode() + { + return ToString().GetHashCode(); + } + + public bool Equals(RECT Rectangle) + { + return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom; + } + + public override bool Equals(object Object) + { + if (Object is RECT) + { + return Equals((RECT)Object); + } + else if (Object is Rectangle) + { + return Equals(new RECT((Rectangle)Object)); + } + + return false; + } + } +} diff --git a/rccscreenshot/rccscreenshot/rccscreenshot.csproj b/rccscreenshot/rccscreenshot/rccscreenshot.csproj new file mode 100644 index 0000000..a3341cd --- /dev/null +++ b/rccscreenshot/rccscreenshot/rccscreenshot.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {D35FDD7F-58B7-42ED-A16E-A793DA507783} + Exe + rccscreenshot + rccscreenshot + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file