• FindWindowEx 这个API函数怎么用?还有第二个参数该怎么写
  • 其他开发语言
    1.00元

using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace findwindow

{

public partial class Form1 : Form
{
   [DllImport("user32.dll", EntryPoint = "FindWindow")]
   private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

   [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
   private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

   public Form1()
   {
       InitializeComponent();
       this.ShowInTaskbar = false;
   }

   private void button1_Click(object sender, EventArgs e)
   {
       //如找到目标窗口显示对应句柄;找不到显示0
       IntPtr hwnd = FindWindow("CalcFrame", "计算器"); //
       if (hwnd != IntPtr.Zero)
       {
           txt.AppendText("发现目示窗口,其句柄是:" + hwnd + "\n");
       }
       else
       {
           txt.AppendText("没有找到目标窗口" + "\n");
       }

       IntPtr sonhwnd = FindWindowEx(hwnd,IntPtr.Zero,"Button", "9");//获取名为“9”的按钮句柄

       if (sonhwnd != IntPtr.Zero)
       {
           txt.AppendText("找到按钮");
       }
       else
       {
           txt.AppendText("句柄号为:" + sonhwnd.ToString() + " 没有找到目标句柄" + "\n");
       }
   }
}


  • Willson1991    2020-05-06 11:08:11
  • 阅读 807    收藏 0    回答 1
  • 邀请
  • 收藏
  • 分享
发送
登录 后发表评论
  • 51testing软件测试圈微信