⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windows.cs

📁 功能:基于windows mobile 的地图查看器。使用vs2005开发
💻 CS
字号:
using System;
using System.Runtime.InteropServices;

namespace PInvokeLibrary
{
	/// <summary>
	/// Summary description for Windows.
	/// </summary>
	public class Windows
	{
		/// <summary>
		/// This function retrieves the handle to the window, if any, that has
		/// captured the mouse or stylus input. Only one window at a time can
		/// capture the mouse or stylus input.
		/// </summary>
		/// <returns>The handle of the capture window associated with the current
		/// thread indicates success. NULL indicates that no window in the current
		/// thread has captured the mouse.</returns>
		[DllImport("coredll.dll")]
		public static extern IntPtr GetCapture();

		/// <summary>
		/// The FindWindow function retrieves the handle to the top-level window whose
		/// class name and window name match the specified strings. This function does
		/// not search child windows.
		/// </summary>
		/// <param name="className">Long pointer to a null-terminated string that
		/// specifies the class name or is an atom that identifies the class-name
		/// string. If this parameter is an atom, it must be a global atom created
		/// by a previous call to the GlobalAddAtom function. The atom, a 16-bit
		/// value, must be placed in the low-order word of lpClassName; the high-order
		/// word must be zero.</param>
		/// <param name="WindowsName">Long pointer to a null-terminated string that
		/// specifies the window name (the window抯 title). If this parameter is NULL,
		/// all window names match.</param>
		/// <returns>A handle to the window that has the specified class name and
		/// window name indicates success. NULL indicates failure. To get extended
		/// error information, call GetLastError.</returns>
		[DllImport("CoreDll")]
		public static extern IntPtr FindWindow(string className, string WindowsName);

		/// <summary>
		/// Hides the window and activates another window.
		/// </summary>
		public const int SW_HIDE = 0;
		/// <summary>
		/// Activates the window and displays it in its current size and position.
		/// </summary>
		public const int SW_SHOW = 5;
		/// <summary>
		/// Displays the window in its current state. The active window remains active.
		/// </summary>
		public const int SW_SHOWNA = 8;
		/// <summary>
		/// Activates and displays a window. If the window is minimized or maximized,
		/// the system restores it to its original size and position. An application
		/// should specify this flag when displaying the window for the first time.
		/// </summary>
		public const int SW_SHOWNORMAL = 1;

		/// <summary>
		/// This function sets the specified window抯 show state.
		/// </summary>
		/// <param name="hwnd">Handle to the window.</param>
		/// <param name="nCmdShow">Specifies how the window is to be shown. The first
		/// time ShowWindow is called, the value should be the value obtained by the
		/// WinMain function in its nCmdShow parameter. In subsequent calls, this
		/// parameter can be one of SW_HIDE, SW_SHOW, SW_SHOWNA, or SW_SHOWNORMAL</param>
		/// <returns>Nonzero indicates that the window was previously visible.
		/// Zero indicates that the window was previously hidden.</returns>
		[DllImport("CoreDll")]
		public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

		/// <summary>
		/// Run a test of the Windows class.
		/// </summary>
		/// <param name="showLine">Delegate called to show debug information</param>
		public static void TestProc(MainTest.DisplayLineDelegate showLine)
		{
			showLine("Creating invisible test form...");

			String findName = "FindMeNowPlease";
			System.Windows.Forms.Form tempForm = new System.Windows.Forms.Form();
			tempForm.Text = findName;
			
			IntPtr hWnd1 = FindWindow(null, findName);
			showLine(String.Format("FindWindow: {0}", hWnd1));

			tempForm.Capture = true;
			IntPtr hWnd2 = GetCapture();
			tempForm.Capture = false;
			showLine(String.Format("GetCapture: {0}", hWnd2));

			if (hWnd1 == IntPtr.Zero || hWnd2 == IntPtr.Zero || hWnd1 != hWnd2)
			{
				showLine("FAILURE: Invalid HWND detected");
			}
			else
			{
				showLine("HWND values match");
			}
			
			showLine("Closing test form...");
			tempForm.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -