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