Win32API.cs
changeset 0 f6eca6facd07
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Win32API.cs	Sat Jun 14 12:51:25 2014 +0200
     1.3 @@ -0,0 +1,100 @@
     1.4 +//=============================================================================
     1.5 +// COPYRIGHT: Prosoft-Lanz
     1.6 +//=============================================================================
     1.7 +//
     1.8 +// $Workfile: Win32API.cs $
     1.9 +//
    1.10 +// PROJECT : CodeProject Components
    1.11 +// VERSION : 1.00
    1.12 +// CREATION : 19.02.2003
    1.13 +// AUTHOR : JCL
    1.14 +//
    1.15 +// DETAILS : This class implement Win32 API calls
    1.16 +//           and the contants used for these calls.
    1.17 +//
    1.18 +//-----------------------------------------------------------------------------
    1.19 +using System;
    1.20 +using System.Text;
    1.21 +using System.Drawing;
    1.22 +using System.Windows.Forms;
    1.23 +using System.Runtime.InteropServices;
    1.24 +
    1.25 +namespace CodeProject.Win32API
    1.26 +{
    1.27 +	///////////////////////////////////////////////////////////////////////
    1.28 +	#region Generic declarations
    1.29 +
    1.30 +	/// <summary>
    1.31 +	/// Rectangle parameters exposed as a structure.
    1.32 +	/// </summary>
    1.33 +	public struct RECT
    1.34 +	{
    1.35 +		/// <summary>
    1.36 +		/// Rectangle members.
    1.37 +		/// </summary>
    1.38 +		public int left, top, right, bottom;
    1.39 +	}
    1.40 +
    1.41 +	#endregion
    1.42 +
    1.43 +	///////////////////////////////////////////////////////////////////////
    1.44 +	#region Util class
    1.45 +
    1.46 +	/// <summary>
    1.47 +	/// Utility functions.
    1.48 +	/// </summary>
    1.49 +	public sealed class API
    1.50 +	{
    1.51 +		private API() {}	// To remove the constructor from the documentation!
    1.52 +
    1.53 +		/// <summary>
    1.54 +		/// Get true multiscreen size.
    1.55 +		/// </summary>
    1.56 +		public static Rectangle TrueScreenRect
    1.57 +		{
    1.58 +			get
    1.59 +			{
    1.60 +				// get the biggest screen area
    1.61 +				Rectangle rectScreen = Screen.PrimaryScreen.WorkingArea;
    1.62 +				int left = rectScreen.Left;
    1.63 +				int top = rectScreen.Top;
    1.64 +				int right = rectScreen.Right;
    1.65 +				int bottom = rectScreen.Bottom;
    1.66 +				foreach (Screen screen in Screen.AllScreens)
    1.67 +				{
    1.68 +					left = Math.Min(left, screen.WorkingArea.Left);
    1.69 +					right = Math.Max(right, screen.WorkingArea.Right);
    1.70 +					top = Math.Min(top, screen.WorkingArea.Top);
    1.71 +					bottom = Math.Max(bottom, screen.WorkingArea.Bottom);
    1.72 +				}
    1.73 +				return new Rectangle(left, top, right-left, bottom-top);
    1.74 +			}
    1.75 +		}
    1.76 +	}
    1.77 +
    1.78 +	#endregion
    1.79 +
    1.80 +	///////////////////////////////////////////////////////////////////////
    1.81 +	#region USER32 class
    1.82 +
    1.83 +	/// <summary>
    1.84 +	/// Class to expose USER32 API functions.
    1.85 +	/// </summary>
    1.86 +	public sealed class USER32
    1.87 +	{
    1.88 +		private USER32() {}	// To remove the constructor from the documentation!
    1.89 +
    1.90 +		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    1.91 +		internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect);
    1.92 +
    1.93 +		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    1.94 +		internal static extern int MoveWindow(IntPtr hWnd, int x, int y, int w, int h, int repaint);
    1.95 +
    1.96 +		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
    1.97 +		internal static extern IntPtr GetActiveWindow();
    1.98 +
    1.99 +		[DllImport("user32", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
   1.100 +		internal static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);
   1.101 +	}
   1.102 +	#endregion
   1.103 +}