diff --git a/bin/ScreenshareHelper.exe b/bin/ScreenshareHelper.exe deleted file mode 100644 index 7ee1951..0000000 Binary files a/bin/ScreenshareHelper.exe and /dev/null differ diff --git a/bin/ScreenshareHelper_x86.exe b/bin/ScreenshareHelper_x86.exe deleted file mode 100644 index 7ee1951..0000000 Binary files a/bin/ScreenshareHelper_x86.exe and /dev/null differ diff --git a/bin/ScreenshareHelper_x64.exe b/bin/x64/ScreenshareHelper.exe similarity index 55% rename from bin/ScreenshareHelper_x64.exe rename to bin/x64/ScreenshareHelper.exe index 4b4ae0c..92b29f8 100644 Binary files a/bin/ScreenshareHelper_x64.exe and b/bin/x64/ScreenshareHelper.exe differ diff --git a/bin/x86/ScreenshareHelper.exe b/bin/x86/ScreenshareHelper.exe new file mode 100644 index 0000000..0f96084 Binary files /dev/null and b/bin/x86/ScreenshareHelper.exe differ diff --git a/readme.md b/readme.md index 0594a83..e98e526 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,7 @@ I started building this tool on .net 5 windows forms, so you should install the ## Download [ScreenshareHelper.exe](https://github.com/michiproep/ScreenshareHelper/tree/master/bin) +Either use x86 or x64 precompiled verion. ## How to use the tool? 1. Start ScreenshareHelper.exe => Transparent window appears @@ -27,6 +28,18 @@ I started building this tool on .net 5 windows forms, so you should install the You can actually move the tool to another screen (if you wish and got one) - once you set the capture area with the set-button. This way you can actually see what's happening +## Command Line Options / SnapToProcess +You can create a .bat file or use a desktop shortcut to add command line options to let the tool snap to a certain process on startup. +Use process name or better process ID (MainWindow process ID) to accomplish this. + +-n => Process name (e.g. firefox) +-i => PID + +Examples +``` +ScreenshareHelper.exe -n notepad2 +ScreenshareHelper.exe -i 12345 +``` ## Donate If you like the tool, just [Paypal.me](https://paypal.me/mlproe?locale.x=de_DE) diff --git a/src/ScreenshareHelper/Options.cs b/src/ScreenshareHelper/Options.cs new file mode 100644 index 0000000..556c96b --- /dev/null +++ b/src/ScreenshareHelper/Options.cs @@ -0,0 +1,13 @@ +using CommandLine; + +namespace ScreenshareHelper +{ + public class Options + { + [Option('n', "processname", Required = false, HelpText = "Process name to snap to at startup.", SetName = "process")] + public string Process { get; set; } + + [Option('i', "pid", Required = false, HelpText = "Process ID to snap to at startup.", SetName = "process")] + public int? ProcessID { get; set; } + } +} diff --git a/src/ScreenshareHelper/Program.cs b/src/ScreenshareHelper/Program.cs index 723a6ef..5284181 100644 --- a/src/ScreenshareHelper/Program.cs +++ b/src/ScreenshareHelper/Program.cs @@ -1,6 +1,10 @@ +using CommandLine; +using ScreenshareHelper.Properties; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; @@ -12,12 +16,88 @@ static class Program /// The main entry point for the application. /// [STAThread] - static void Main() + static void Main(string[] args) { + Parser.Default.ParseArguments(args). + WithParsed(o => + { + if (!string.IsNullOrEmpty(o.Process)) + SnapToProcess(o.Process); + else if (o.ProcessID.HasValue) + SnapToProcess(o.ProcessID.Value); + } + ); + Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } + + + #region SnapToProcess + private static void SnapToProcess(int processID) + { + var p = System.Diagnostics.Process.GetProcessById(processID); + if(p != null && p.MainWindowHandle != IntPtr.Zero) + { + if(GetWindowRect(p.MainWindowHandle, out RECT r)) + { + r = GetWindowBounds(p.MainWindowHandle); + Settings.Default.CaptureLocation = new System.Drawing.Point(r.left, r.top); + Settings.Default.CaptureSize = new System.Drawing.Size(r.right -r.left, r.bottom -r.top); + Settings.Default.Save(); + } + } + } + + private static void SnapToProcess(string process) + { + //find process + var tmp = System.Diagnostics.Process.GetProcesses(); + var p = System.Diagnostics.Process.GetProcessesByName(process).FirstOrDefault(); + if (p != null) + SnapToProcess(p.Id); + } + #endregion + + #region Win32 + + [StructLayout(LayoutKind.Sequential)] + public struct RECT + { + public int left; + public int top; + public int right; + public int bottom; + } + + [DllImport("user32.dll", SetLastError = true)] + static extern bool GetWindowRect(IntPtr hWnd, out RECT Rect); + + [DllImport("dwmapi.dll")] + static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, IntPtr pvAttribute, int cbAttribute); + + public static RECT GetWindowBounds(IntPtr handle) + { + RECT rect; + if (Environment.OSVersion.Version.Major < 6) + { + //Is Below Vista (exclusive) + if (!GetWindowRect(handle, out rect)) + throw new Win32Exception(Marshal.GetLastWin32Error()); + return rect; + } + //Vista (inclusive) and above will include shadows in GetWindowRect. + IntPtr ptrFrame = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(RECT))); + int ret = DwmGetWindowAttribute(handle, /*(int)DWMWA.EXTENDED_FRAME_BOUNDS*/ 9, ptrFrame, Marshal.SizeOf(typeof(RECT))); + if (ret != 0) + throw new Win32Exception(ret); + rect = (RECT)Marshal.PtrToStructure(ptrFrame, typeof(RECT)); + Marshal.FreeHGlobal(ptrFrame); + return rect; + } + + #endregion } } diff --git a/src/ScreenshareHelper/Properties/launchSettings.json b/src/ScreenshareHelper/Properties/launchSettings.json new file mode 100644 index 0000000..e955c70 --- /dev/null +++ b/src/ScreenshareHelper/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "ScreenshareHelper": { + "commandName": "Project", + "commandLineArgs": "-i 35188" + } + } +} \ No newline at end of file diff --git a/src/ScreenshareHelper/ScreenshareHelper.csproj b/src/ScreenshareHelper/ScreenshareHelper.csproj index 64d8057..3a7fa61 100644 --- a/src/ScreenshareHelper/ScreenshareHelper.csproj +++ b/src/ScreenshareHelper/ScreenshareHelper.csproj @@ -5,9 +5,12 @@ net5.0-windows true rocket_startup_monitor_screen_computer_icon_124621.ico - true + + + + True