//\\//\\//\\//\\//\\//\\//\\//\\//\\ // MyToolBox.cs AppStatic Assembly // Tools and Dialogs among others. //\\//\\//\\//\\//\\//\\//\\//\\//\\ // Brought over from Smesav Project // AppStatic.Tools & .Dialogs are // Independent like MyCustomControl // v2.3.7.27 15-Dec-2018 -JpE- //\\//\\//\\//\\//\\//\\//\\//\\//\\ using System; using System.IO; using System.Diagnostics; using System.Runtime.InteropServices; using System.Security; namespace MyCustomLibrary { #region MyToolBox Class public class MyToolBox { /// Opens the parm folder for them. /// public static void OpenFolder(string directory) { if (!Directory.Exists(directory)) return; RunApp(directory, "explorer.exe"); } /// Multiple OverLoads; This /// Overload whereIn first element of array /// is the Application Name; per Standard /// for Command Line Args in Windows. /// v2.6.0.32 14-Feb-2018 /// /// public static void RunApp(string[] args) { var str = ""; for (var s = 1; s < args.Length; ++s) str += string.Format( "\"{0}\" ", args[s]); RunApp(str, args[0]); } /// Primarily for Show Me Viewer /// May be ReUsable moreover L8r. /// /// /// /// public static void RunApp( string txt, string ttl, string nme) { var s = string.Format( "\"{0}\" \"{1}\"", txt, ttl); RunApp(s, nme); } /// OverLoads Break down to This1. /// First element may or may not be App name. /// /// /// public static void RunApp(string args, string name) { var startInfo = new ProcessStartInfo { FileName = name, Arguments = args }; Process.Start(startInfo); } } #endregion MyToolBox Class //\\//\\//\\//\\//\\//\\//\\//\\//\\ //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// // NOTE: The Below is a Separate-Class!!!! //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// #region SafeNativeMethods Static Class // Special little class of cool tricks. [SuppressUnmanagedCodeSecurity] public static class SafeNativeMethods { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [DllImport("user32.dll")] private static extern bool SetForegroundWindow( IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindowAsync( IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] private static extern bool IsIconic( IntPtr hWnd); // My Custom Class and Public Method // Brings called Window to front in // Windows from another App or 2nd instance // of your App to communicate to the 1st. public static void B2F(IntPtr hWnd) { if (IsIconic(hWnd)) ShowWindowAsync(hWnd, 9); SetForegroundWindow(hWnd); } } #endregion SNM //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\// }