www.pudn.com > sudoku.rar > NativeMethods.cs


//-------------------------------------------------------------------------- 
//  
//  Copyright (c) Microsoft Corporation.  All rights reserved.  
//  
//  File: NativeMethods.cs 
// 
//  Description: Win32 P/Invoke methods and values 
//  
//-------------------------------------------------------------------------- 
 
using System; 
using System.Runtime.InteropServices; 
 
namespace Microsoft.Sudoku 
{ 
	/// P/Invoke methods and values. 
	internal sealed class NativeMethods 
	{ 
		/// Prevent external instantiation. 
		private NativeMethods(){} 
 
		///  
		/// The GetSystemMetrics function retrieves various system metrics (widths and  
		/// heights of display elements) and system configuration settings. All dimensions  
		/// retrieved by GetSystemMetrics are in pixels. 
		///  
		/// System metric or configuration setting to retrieve. 
		///  
		/// If the function succeeds, the return value is the requested system metric or configuration setting. 
		/// If the function fails, the return value is zero. 
		///  
		[DllImport("user32.dll", CharSet=CharSet.Auto)] 
		internal static extern int GetSystemMetrics(int nIndex); 
 
		///  
		/// Determines whether pop-up menus are left-aligned or right-aligned, relative to the corresponding  
		/// menu-bar item. The pvParam parameter must point to a BOOL variable that receives TRUE if left-aligned,  
		/// or FALSE otherwise. 
		///  
		internal const uint SPI_GETMENUDROPALIGNMENT = 27; 
 
		/// Index used with GetSystemMetrics to determine whether the current machine is a Tablet PC. 
		internal const int SM_TABLETPC = 86; 
		 
		/// The GetCurrentProcessId function retrieves the process identifier of the calling process. 
		/// The return value is the process identifier of the calling process. 
		[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern uint GetCurrentProcessId(); 
 
		///  
		/// The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window  
		/// and, optionally, the identifier of the process that created the window.  
		///  
		/// Handle to the window. 
		/// Pointer to a variable that receives the process identifier. 
		/// The return value is the identifier of the thread that created the window. 
		[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern int GetWindowThreadProcessId(HandleRef handle, out uint processId); 
 
		/// The GetWindow function retrieves a handle to a window that has the specified  
		/// relationship (Z-Order or owner) to the specified window. 
		/// Handle to a window. 
		/// Specifies the relationship between the specified window and the window whose handle is to be retrieved. 
		///  
		/// If the function succeeds, the return value is a window handle.  
		/// If no window exists with the specified relationship to the specified window, the return value is NULL. 
		///  
		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
		internal static extern IntPtr GetWindow(HandleRef hWnd, int uCmd); 
 
		/// The IsWindowVisible function retrieves the visibility state of the specified window. 
		/// Handle to the window to test. 
		///  
		/// If the specified window, its parent window, its parent's parent window, and so forth, have the WS_VISIBLE style,  
		/// the return value is nonzero. Otherwise, the return value is zero.  
		///  
		[DllImport("user32.dll", CharSet=CharSet.Auto)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool IsWindowVisible(HandleRef hWnd); 
 
		///  
		/// The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn,  
		/// to an application-defined callback function. EnumWindows continues until the last top-level window is  
		/// enumerated or the callback function returns FALSE. 
		///  
		/// Pointer to an application-defined callback function. 
		/// Specifies an application-defined value to be passed to the callback function. 
		/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. 
		[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool EnumWindows(NativeMethods.EnumThreadWindowsCallback callback, IntPtr extraData); 
 
		/// Delegate used for callbacks from EnumWindows. 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam); 
 
		/// The ShowWindowAsync function sets the show state of a window created by a different thread. 
		/// Handle to the window. 
		/// Specifies how the window is to be shown. 
		///  
		/// If the window was previously visible, the return value is nonzero. If the window was previously hidden, the return value is zero. 
		///  
		[DllImport("User32.dll")] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow); 
 
		///  
		/// The SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window.  
		///  
		/// Handle to the window that should be activated and brought to the foreground. 
		///  
		/// If the window was brought to the foreground, the return value is nonzero. 
		/// If the window was not brought to the foreground, the return value is zero. 
		///  
		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool SetForegroundWindow(HandleRef hWnd); 
 
		///  
		/// The CreateFileMapping function creates or opens a named or unnamed file mapping object for the specified file. 
		///  
		/// Handle to the file from which to create a mapping object. 
		///  
		/// Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. 
		///  
		/// Protection desired for the file view, when the file is mapped. 
		/// High-order DWORD of the maximum size of the file mapping object. 
		/// Low-order DWORD of the maximum size of the file mapping object. 
		/// Pointer to a null-terminated string specifying the name of the mapping object. 
		///  
		/// If the function succeeds, the return value is a handle to the file mapping object. If the object existed before the function call, the function  
		/// returns a handle to the existing object (with its current size, not the specified size) and GetLastError returns ERROR_ALREADY_EXISTS.  
		/// If the function fails, the return value is NULL. 
		///  
		[DllImport("Kernel32", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern IntPtr CreateFileMapping(IntPtr hFile,  
			IntPtr lpAttributes, int flProtect, int dwMaxSizeHi, int dwMaxSizeLow, string lpName); 
 
		/// The OpenFileMapping function opens a named file mapping object. 
		/// Access to the file mapping object. 
		/// If this parameter is TRUE, the new process inherits the handle. Otherwise, it does not. 
		///  
		/// Pointer to a string that names the file mapping object to be opened. If there is an open handle to a file mapping  
		/// object by this name and the security descriptor on the mapping object does not conflict with the dwDesiredAccess  
		/// parameter, the open operation succeeds. 
		///  
		///  
		/// If the function succeeds, the return value is an open handle to the specified file mapping object. 
		/// If the function fails, the return value is NULL. 
		///  
		[DllImport("Kernel32", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern IntPtr OpenFileMapping(int dwDesiredAccess,  
			[MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, string lpName); 
 
		///  
		/// The MapViewOfFile function maps a view of a file into the address space of the calling process. 
		///  
		/// Handle to an open handle of a file mapping object. 
		/// Type of access to the file view and, therefore, the protection of the pages mapped by the file. 
		/// High-order DWORD of the file offset where mapping is to begin. 
		/// Low-order DWORD of the file offset where mapping is to begin. 
		/// Number of bytes of the file to map. If this parameter is zero, the entire file is mapped. 
		///  
		/// If the function succeeds, the return value is the starting address of the mapped view. 
		/// If the function fails, the return value is NULL. 
		///  
		[DllImport("Kernel32", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern IntPtr MapViewOfFile(IntPtr hFileMapping,  
			int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, int dwNumberOfBytesToMap); 
 
		///  
		/// The UnmapViewOfFile function unmaps a mapped view of a file from the calling process's address space. 
		///  
		/// Pointer to the base address of the mapped view of a file that is to be unmapped. 
		///  
		/// If the function succeeds, the return value is nonzero, and all dirty pages within the specified range are written "lazily" to disk. 
		/// If the function fails, the return value is zero. 
		///  
		[DllImport("Kernel32", CharSet=CharSet.Auto, SetLastError=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool UnmapViewOfFile(IntPtr pvBaseAddress); 
 
		/// The CloseHandle function closes an open object handle. 
		/// The CloseHandle function closes an open object handle. 
		/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. 
		[DllImport("kernel32.dll", SetLastError=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool CloseHandle(IntPtr handle); 
		 
		///  
		/// The SendMessage function sends the specified message to a window or windows.  
		/// It calls the window procedure for the specified window and does not return until the window procedure has processed the message.  
		///  
		/// Handle to the window whose window procedure will receive the message. 
		/// Specifies the message to be sent. 
		/// Specifies additional message-specific information. 
		/// Specifies additional message-specific information. 
		/// The return value specifies the result of the message processing; it depends on the message sent. 
		[DllImport("user32.dll", CharSet=CharSet.Auto)] 
		internal static extern IntPtr SendMessage(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam); 
 
		/// Registers specific common control classes from the common control dynamic-link library (DLL). 
		/// Pointer to an INITCOMMONCONTROLSEX structure that contains information specifying which control classes will be registered. 
		/// Returns TRUE if successful, or FALSE otherwise. 
		[DllImport("comctl32.dll")] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc); 
  
		/// Carries information used to load common control classes from the dynamic-link library (DLL). 
		[StructLayout(LayoutKind.Sequential, Pack=1)] 
		internal class INITCOMMONCONTROLSEX 
		{ 
			/// Size of the structure, in bytes. 
			public int dwSize; 
			/// Set of bit flags that indicate which common control classes will be loaded from the DLL. 
			public int dwICC; 
		} 
 
		/// The GetWindowPlacement function retrieves the show state and the restored, minimized, and maximized positions of the specified window. 
		/// Handle to the window. 
		/// Pointer to the WINDOWPLACEMENT structure that receives the show state and position information. 
		/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. 
		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool GetWindowPlacement(HandleRef hWnd, ref WINDOWPLACEMENT placement); 
 
		/// The IsIconic function determines whether the specified window is minimized (iconic). 
		/// Handle to the window to test. 
		/// If the window is iconic, the return value is nonzero. If the window is not iconic, the return value is zero. 
		[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool IsIconic(HandleRef hWnd); 
 
		/// The WINDOWPLACEMENT structure contains information about the placement of a window on the screen. 
		[StructLayout(LayoutKind.Sequential)] 
			internal struct WINDOWPLACEMENT 
		{ 
			/// Specifies the length, in bytes, of the structure. 
			public int length; 
			/// Specifies flags that control the position of the minimized window and the method by which the window is restored. 
			public int flags; 
			/// Specifies the current show state of the window. 
			public int showCmd; 
			/// Specifies the X coordinate of the window's upper-left corner when the window is minimized. 
			public int ptMinPosition_x; 
			/// Specifies the Y coordinate of the window's upper-left corner when the window is minimized. 
			public int ptMinPosition_y; 
			/// Specifies the X coordinate of the window's upper-left corner when the window is maximized. 
			public int ptMaxPosition_x; 
			/// Specifies the Y coordinate of the window's upper-left corner when the window is maximized. 
			public int ptMaxPosition_y; 
			/// Specifies the window's left coordinate when the window is in the restored position. 
			public int rcNormalPosition_left; 
			/// Specifies the window's top coordinate when the window is in the restored position. 
			public int rcNormalPosition_top; 
			/// Specifies the window's right coordinate when the window is in the restored position. 
			public int rcNormalPosition_right; 
			/// Specifies the window's bottom coordinate when the window is in the restored position. 
			public int rcNormalPosition_bottom; 
		} 
 
		/// The GetCurrentProcess function retrieves a pseudo handle for the current process. 
		/// The return value is a pseudo handle to the current process. 
		[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		internal static extern IntPtr GetCurrentProcess(); 
 
		///  
		/// The SystemParametersInfo function retrieves or sets the value of  
		/// one of the system-wide parameters. This function can also update the user profile while setting a parameter. 
		///  
		/// System-wide parameter to be retrieved or set. 
		/// Depends on the system parameter being queried or set. 
		/// Depends on the system parameter being queried or set. 
		/// If a system parameter is being set, specifies whether the user profile is to be updated. 
		///  
		/// If the function succeeds, the return value is a nonzero value. 
		/// If the function fails, the return value is zero. 
		///  
		[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool SystemParametersInfo(uint uiAction, uint uiParam,  
			[MarshalAs(UnmanagedType.Bool)] ref bool pvParam, uint fWinIni); 
 
		/// The SetProcessWorkingSetSize function sets the minimum and maximum working set sizes for the specified process. 
		/// Handle to the process whose working set sizes is to be set. 
		/// Minimum working set size for the process, in bytes. 
		/// Maximum working set size for the process, in bytes. 
		/// If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. 
		[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)] 
		[return: MarshalAs(UnmanagedType.Bool)] 
		internal static extern bool SetProcessWorkingSetSize(IntPtr hProcess, IntPtr dwMinimumWorkingSetSize, IntPtr dwMaximumWorkingSetSize); 
	} 
}