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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM