//\\//\\//\\//\\//\\//\\//\\//\\//\\
// 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
{
/// <summary> Opens the parm folder for them.
/// </summary>
public static void
OpenFolder(string directory)
{
if (!Directory.Exists(directory)) return;
RunApp(directory, "explorer.exe");
}
/// <summary> 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
/// </summary>
/// <param name="args"></param>
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]);
}
/// <summary> Primarily for Show Me Viewer
/// May be ReUsable moreover L8r.
/// </summary>
/// <param name="txt"></param>
/// <param name="ttl"></param>
/// <param name="nme"></param>
public static void RunApp(
string txt, string ttl, string nme)
{
var s = string.Format(
"\"{0}\" \"{1}\"", txt, ttl);
RunApp(s, nme);
}
/// <summary> OverLoads Break down to This1.
/// First element may or may not be App name.
/// </summary>
/// <param name="args"></param>
/// <param name="name"></param>
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
//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
}
Comments
0 B
|👍
/👎