Advertisement
GlobalAccessSoftware

Win32.API SafeNativeCode Class

May 26th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. #region SafeNativeMethods Static Class
  2.  
  3.   // Special little class of cool tricks.
  4.   [SuppressUnmanagedCodeSecurity]
  5.   public static class SafeNativeMethods
  6.   { // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  7.    
  8.     [DllImport("user32.dll")]
  9.     private static extern bool
  10.       SetForegroundWindow(
  11.         IntPtr hWnd);
  12.  
  13.     [DllImport("user32.dll")]
  14.     private static extern bool
  15.       ShowWindowAsync(
  16.         IntPtr hWnd, int nCmdShow);
  17.  
  18.     [DllImport("user32.dll")]
  19.     private static extern bool
  20.       IsIconic(
  21.         IntPtr hWnd);
  22.  
  23.     // My Custom Class and Public Method
  24.     // Brings called Window to front in
  25.     // Windows from another App or 2nd instance
  26.     // of your App to communicate to the 1st.
  27.     public static void B2F(IntPtr hWnd)
  28.     {
  29.       if (IsIconic(hWnd))
  30.         ShowWindowAsync(hWnd, 9);
  31.       SetForegroundWindow(hWnd);
  32.     }
  33.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement