⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32enumwindows.cs

📁 Introduction Sometimes you may collide with the following problem: a third-party binary component o
💻 CS
字号:
//********************************************************************************************
//Author: Sergey Stoyan, CliverSoft Co.
//        stoyan@cliversoft.com
//        sergey.stoyan@gmail.com
//        http://www.cliversoft.com
//        07 September 2006
//Copyright: (C) 2006, Sergey Stoyan
//********************************************************************************************
using System;
using System.Threading;
//using System.Messaging;
using System.Text;
using System.Configuration;
using System.Collections; 

namespace CliverSoft
{
    /// <summary>
    /// contains collected window info
    /// </summary>
	public struct Window
	{
		public string path;
		public string text;
		public string internal_text;
		public string class_name;
		public int level;
		public int parent_id;
	}


	public class EnumWindows
	{
		public ArrayList Windows = new ArrayList();

        /// <summary>
        /// enum all windows including child windows
        /// </summary>
        /// <param name="print_to_log"></param>
		public EnumWindows(bool print_to_log)
		{
            //Print2Log = print_to_log;
			Windows.Clear();
            Win32.Functions.EnumWindows(new Win32.Functions.EnumProc(this.enum_window_call_back), 0);
//			Message.Inform("Completed");
		}

        /// <summary>
        /// invoke building child window tree for give parent window
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="lValue"></param>
        /// <returns></returns>
		bool enum_window_call_back(IntPtr hwnd, int lValue) 
		{
			Window w = new Window();

			w.level = 0;
			w.parent_id = -1;

			StringBuilder s = new StringBuilder(255);;
					
			Win32.Functions.GetClassName(hwnd, s, 255);
			w.class_name = s.ToString();
			Win32.Functions.GetWindowText(hwnd, s, 255);
			w.text = s.ToString();
			Win32.Functions.InternalGetWindowText(hwnd, s, 255);
			w.internal_text = s.ToString();
			w.path = "[" + w.text + "]";

			Windows.Add(w);
					
			//Message.Write2Log(w.level + " " + w.path + " - " + w.class_name);

            Win32.Functions.EnumChildWindows(hwnd, new Win32.Functions.EnumProc(this.enum_child_window_call_back), Windows.Count - 1);			
					
			return true;
		}

        /// <summary>
        /// build child window tree recurcively
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="parent_id"></param>
        /// <returns></returns>
        bool enum_child_window_call_back(IntPtr hwnd, int parent_id) 
		{
			Window w = new Window();

			w.level = ((Window)Windows[parent_id]).level + 1;
			w.parent_id = parent_id;

			StringBuilder s = new StringBuilder(255);
					
			Win32.Functions.GetClassName(hwnd, s, 255);
			w.class_name = s.ToString();
			Win32.Functions.GetWindowText(hwnd, s, 255);
			w.text = s.ToString();
			Win32.Functions.InternalGetWindowText(hwnd, s, 255);
			w.internal_text = s.ToString();
			w.path = ((Window)Windows[parent_id]).path + "[" + w.text + "]";

			Windows.Add(w);
					
			//Message.Write2Log(w.level + " " + w.path + " - " + w.class_name);

            Win32.Functions.EnumChildWindows(hwnd, new Win32.Functions.EnumProc(this.enum_child_window_call_back), Windows.Count - 1);			
					
			return true;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -