zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    人生感悟:人与人之间的距离
    9月22日测试题目
    Java自学第五十二天
    Java自学第五十一天
    Java自学第五十天
    Java自学第四十九天
    Java自学第四十八天
    Java自学第四十七天
    Java自学第四十六天
    Java自学第四十五天
  • 原文地址:https://www.cnblogs.com/enjoyprogram/p/2779129.html
Copyright © 2011-2022 走看看