根據標題獲取窗口句柄
using System; using System.Runtime.InteropServices; namespace tstfindwindow { /// /// Class1 的摘要說明。 /// class Class1 { [DllImport( "User32.dll ")] public static extern System. IntPtr FindWindowEx(System. IntPtr parent, System. IntPtr childe, string strclass, string strname); /// /// 應用程序的主入口點。 /// [STAThread] static void Main(string[] args) { // //TODO: 在此處添加代碼以啟動應用程序 // IntPtr p=FindWindowEx(System.IntPtr.Zero,System.IntPtr.Zero,null,"窗口標題"); } }
發送消息控制最大、最小
[DllImport("user32.dll", EntryPoint = "PostMessage")] public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x112; public const int SC_MINIMIZE = 0xF020; public const int SC_MAXIMIZE = 0xF030; private void button1_Click(object sender, EventArgs e) { PostMessage(Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0); }