Ejemplo n.º 1
0
        /// <summary>
        /// Build the ApiWindow object to hold information about the Window object.
        /// </summary>
        private ApiWindow GetWindowIdentification(int hwnd)
        {
            const Int32 WM_GETTEXT       = 13;
            const Int32 WM_GETTEXTLENGTH = 14;

            ApiWindow window = new ApiWindow();

            StringBuilder title = new StringBuilder();

            // Get the size of the string required to hold the window title.
            Int32 size = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);

            // If the return is 0, there is no title.
            if (size > 0)
            {
                title = new StringBuilder(size + 1);

                SendMessage(hwnd, WM_GETTEXT, title.Capacity, title);
            }

            // Get the class name for the window.
            StringBuilder classBuilder = new StringBuilder(64);

            GetClassName(hwnd, classBuilder, 64);

            // Set the properties for the ApiWindow object.
            window.ClassName       = classBuilder.ToString();
            window.MainWindowTitle = title.ToString();
            window.hWnd            = hwnd;

            return(window);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Callback function that does the work of enumerating top-level windows.
        /// </summary>
        /// <param name="hwnd">Discovered Window handle</param>
        /// <returns>1=keep going, 0=stop</returns>
        private Int32 EnumWindowProc(Int32 hwnd, Int32 lParam)
        {
            // Eliminate windows that are not top-level.
            if (GetParent(hwnd) == 0 && Convert.ToBoolean(IsWindowVisible(hwnd)))
            {
                // Get the window title / class name.
                ApiWindow window = GetWindowIdentification(hwnd);

                //Match the class name if searching for a specific window class.
                if (_topLevelClass.Length == 0 || window.ClassName.ToLower() == _topLevelClass.ToLower())
                {
                    _listTopLevel.Add(window);
                }
            }

            // To continue enumeration, return True (1), and to stop enumeration
            // return False (0).
            // When 1 is returned, enumeration continues until there are no
            // more windows left.

            return(1);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Callback function that does the work of enumerating child windows.
        /// </summary>
        /// <param name="hwnd">Discovered Window handle</param>
        /// <returns>1=keep going, 0=stop</returns>
        private Int32 EnumChildWindowProc(Int32 hwnd, Int32 lParam)
        {
            ApiWindow window = GetWindowIdentification(hwnd);

            // Attempt to match the child class, if one was specified, otherwise
            // enumerate all the child windows.
            //if (_childClass.Length == 0 || window.ClassName.ToLower() == _childClass.ToLower())
            //{
            //    _listChildren.Add(window);
            //}

            IntPtr        intPtr = new IntPtr(7415142);
            int           len    = 200;// GetWindowTextLength(hWnd) + 1;
            StringBuilder sb     = new StringBuilder(len);

            len = GetWindowText(intPtr, sb, len);
            _listChildren.Add(new ApiWindow()
            {
                MainWindowTitle = "get text = " + sb.ToString(0, len)
            });

            return(1);
        }