Win32API.cs
author sl
Tue, 12 Aug 2014 20:37:57 +0200
changeset 17 19c1aaf900dc
permissions -rw-r--r--
Adding WCF server implementation.
     1 //=============================================================================
     2 // COPYRIGHT: Prosoft-Lanz
     3 //=============================================================================
     4 //
     5 // $Workfile: Win32API.cs $
     6 //
     7 // PROJECT : CodeProject Components
     8 // VERSION : 1.00
     9 // CREATION : 19.02.2003
    10 // AUTHOR : JCL
    11 //
    12 // DETAILS : This class implement Win32 API calls
    13 //           and the contants used for these calls.
    14 //
    15 //-----------------------------------------------------------------------------
    16 using System;
    17 using System.Text;
    18 using System.Drawing;
    19 using System.Windows.Forms;
    20 using System.Runtime.InteropServices;
    21 
    22 namespace CodeProject.Win32API
    23 {
    24 	///////////////////////////////////////////////////////////////////////
    25 	#region Generic declarations
    26 
    27 	/// <summary>
    28 	/// Rectangle parameters exposed as a structure.
    29 	/// </summary>
    30 	public struct RECT
    31 	{
    32 		/// <summary>
    33 		/// Rectangle members.
    34 		/// </summary>
    35 		public int left, top, right, bottom;
    36 	}
    37 
    38 	#endregion
    39 
    40 	///////////////////////////////////////////////////////////////////////
    41 	#region Util class
    42 
    43 	/// <summary>
    44 	/// Utility functions.
    45 	/// </summary>
    46 	public sealed class API
    47 	{
    48 		private API() {}	// To remove the constructor from the documentation!
    49 
    50 		/// <summary>
    51 		/// Get true multiscreen size.
    52 		/// </summary>
    53 		public static Rectangle TrueScreenRect
    54 		{
    55 			get
    56 			{
    57 				// get the biggest screen area
    58 				Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
    59 				int left = rectScreen.Left;
    60 				int top = rectScreen.Top;
    61 				int right = rectScreen.Right;
    62 				int bottom = rectScreen.Bottom;
    63 				foreach (Screen screen in Screen.AllScreens)
    64 				{
    65 					left = Math.Min(left, screen.WorkingArea.Left);
    66 					right = Math.Max(right, screen.WorkingArea.Right);
    67 					top = Math.Min(top, screen.WorkingArea.Top);
    68 					bottom = Math.Max(bottom, screen.WorkingArea.Bottom);
    69 				}
    70 				return new Rectangle(left, top, right-left, bottom-top);
    71 			}
    72 		}
    73 	}
    74 
    75 	#endregion
    76 
    77 	///////////////////////////////////////////////////////////////////////
    78 	#region USER32 class
    79 
    80 	/// <summary>
    81 	/// Class to expose USER32 API functions.
    82 	/// </summary>
    83 	public sealed class USER32
    84 	{
    85 		private USER32() {}	// To remove the constructor from the documentation!
    86 
    87 		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    88 		internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect);
    89 
    90 		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    91 		internal static extern int MoveWindow(IntPtr hWnd, int x, int y, int w, int h, int repaint);
    92 
    93 		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    94 		internal static extern IntPtr GetActiveWindow();
    95 
    96 		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    97 		internal static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);
    98 	}
    99 	#endregion
   100 }