GlobalAccessSoftware

Cool little tricks I've learned, enjoy!

May 17th, 2018
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1.  
  2.  
  3. //\\//\\//\\//\\//\\//\\//\\//\\//\\
  4. // MyToolBox.cs AppStatic Assembly
  5. // Tools and Dialogs among others.
  6. //\\//\\//\\//\\//\\//\\//\\//\\//\\
  7. // Brought over from Smesav Project
  8. // AppStatic.Tools & .Dialogs are
  9. // Independent like MyCustomControl
  10. // v2.3.7.27 15-Dec-2018 -JpE-
  11. //\\//\\//\\//\\//\\//\\//\\//\\//\\
  12.  
  13. using System;
  14. using System.IO;
  15. using System.Diagnostics;
  16. using System.Runtime.InteropServices;
  17. using System.Security;
  18.  
  19. namespace MyCustomLibrary
  20. {
  21. #region MyToolBox Class
  22.  
  23.   public class MyToolBox
  24.   {
  25.     /// <summary> Opens the parm folder for them.
  26.     /// </summary>
  27.     public static void
  28.       OpenFolder(string directory)
  29.     {
  30.       if (!Directory.Exists(directory)) return;
  31.       RunApp(directory, "explorer.exe");
  32.     }
  33.  
  34.     /// <summary> Multiple OverLoads; This
  35.     /// Overload whereIn first element of array
  36.     /// is the Application Name; per Standard
  37.     /// for Command Line Args in Windows.
  38.     /// v2.6.0.32 14-Feb-2018
  39.     /// </summary>
  40.     /// <param name="args"></param>
  41.     public static void RunApp(string[] args)
  42.     {
  43.       var str = "";
  44.       for (var s = 1; s < args.Length; ++s)
  45.         str += string.Format(
  46.           "\"{0}\" ", args[s]);
  47.       RunApp(str, args[0]);
  48.     }
  49.  
  50.     /// <summary> Primarily for Show Me Viewer
  51.     /// May be ReUsable moreover L8r.
  52.     /// </summary>
  53.     /// <param name="txt"></param>
  54.     /// <param name="ttl"></param>
  55.     /// <param name="nme"></param>
  56.     public static void RunApp(
  57.       string txt, string ttl, string nme)
  58.     {
  59.       var s = string.Format(
  60.         "\"{0}\" \"{1}\"", txt, ttl);
  61.       RunApp(s, nme);
  62.     }
  63.  
  64.     /// <summary> OverLoads Break down to This1.
  65.     /// First element may or may not be App name.
  66.     /// </summary>
  67.     /// <param name="args"></param>
  68.     /// <param name="name"></param>
  69.     public static void
  70.       RunApp(string args, string name)
  71.     {
  72.       var startInfo =
  73.         new ProcessStartInfo
  74.         {
  75.           FileName  = name,
  76.           Arguments = args
  77.         };
  78.       Process.Start(startInfo);
  79.     }
  80.   }
  81. #endregion MyToolBox Class
  82.   //\\//\\//\\//\\//\\//\\//\\//\\//\\
  83.  
  84.  
  85.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  86.   // NOTE: The Below is a Separate-Class!!!!
  87.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  88.  
  89. #region SafeNativeMethods Static Class
  90.  
  91.   // Special little class of cool tricks.
  92.   [SuppressUnmanagedCodeSecurity]
  93.   public static class SafeNativeMethods
  94.   { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  95.    
  96.     [DllImport("user32.dll")]
  97.     private static extern bool
  98.       SetForegroundWindow(
  99.         IntPtr hWnd);
  100.  
  101.     [DllImport("user32.dll")]
  102.     private static extern bool
  103.       ShowWindowAsync(
  104.         IntPtr hWnd, int nCmdShow);
  105.  
  106.     [DllImport("user32.dll")]
  107.     private static extern bool
  108.       IsIconic(
  109.         IntPtr hWnd);
  110.  
  111.     // My Custom Class and Public Method
  112.     // Brings called Window to front in
  113.     // Windows from another App or 2nd instance
  114.     // of your App to communicate to the 1st.
  115.     public static void B2F(IntPtr hWnd)
  116.     {
  117.       if (IsIconic(hWnd))
  118.         ShowWindowAsync(hWnd, 9);
  119.       SetForegroundWindow(hWnd);
  120.     }
  121.   }
  122. #endregion SNM
  123.   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
  124.  
  125.  
  126.  
  127. }
Add Comment
Please, Sign In to add comment