C#可调用API接口来获取窗口句柄,发送消息控制其余程序窗体大小

根据标题获取窗口句柄

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);
}
原文地址:https://www.cnblogs.com/enjoyprogram/p/2779129.html