//调用
            ListTitleHandle = new List<IntPtr>();
            var r =  EnumWindows(PrintWindow, "计算器");



        //函数指针类型
        delegate bool deleWindowsProc(IntPtr hWnd, string lParam);

        [DllImport("user32.dll")]
        static extern int EnumWindows(deleWindowsProc hWnd, string lParam);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int GetWindowText(IntPtr hWnd, StringBuilder lpText, int nCount);

        //存储句柄集合
        List<IntPtr> ListTitleHandle;
        //回调函数
        bool PrintWindow(IntPtr hWnd, string lParam)
        {
            //分配空间
            var sb = new StringBuilder(50);
            GetWindowText(hWnd, sb, sb.Capacity);
            //注意某些窗口没有标题
            if (sb.ToString() != String.Empty && sb.ToString().Equals(lParam))
            {
                Console.WriteLine(sb.ToString());
                ListTitleHandle.Add(hWnd);
            }
            //返回True继续往下回调,返回False终止
            return true;
        }

 

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2022-01-02
相关资源
相似解决方案