Esempio n. 1
0
        public WindowInfo GetWindowInfo()
        {
            var process = Process;
            var info    = new WindowInfo();

            info.GetWindowText      = GetWindowText();
            info.WM_GETTEXT         = WindowUtils.GetWmGettext(Handle);
            info.GetClassName       = GetClassName();
            info.RealGetWindowClass = RealGetWindowClass();
            info.Handle             = Handle;
            info.ParentHandle       = GetParent(Handle);
            info.Size         = Size;
            info.ClientSize   = ClientSize;
            info.FrameBounds  = GetSystemMargins();
            info.ProcessId    = ProcessId;
            info.ThreadId     = WindowUtils.GetThreadId(Handle);
            info.GWL_STYLE    = GetWindowLong(Handle, GWL_STYLE);
            info.GWL_EXSTYLE  = GetWindowLong(Handle, GWL_EXSTYLE);
            info.GWL_ID       = GetWindowLong(Handle, GWL_ID);
            info.GWL_USERDATA = GetWindowLong(Handle, GWL_USERDATA);
            info.GCL_STYLE    = GetClassLong(Handle, GCL_STYLE);
            info.GCL_WNDPROC  = GetClassLong(Handle, GCL_WNDPROC);
            info.DWL_DLGPROC  = GetClassLong(Handle, DWL_DLGPROC);
            info.DWL_USER     = GetClassLong(Handle, DWL_USER);
            info.FullPath     = process?.GetMainModuleFileName() ?? "";
            info.Priority     = ProcessPriority;
            info.StartTime    = process == null ? (DateTime?)null : process.StartTime;

            try
            {
                var processInfo = SystemUtils.GetWmiProcessInfo(process.Id);
                info.Owner          = processInfo.Owner;
                info.CommandLine    = processInfo.CommandLine;
                info.ThreadCount    = processInfo.ThreadCount;
                info.HandleCount    = processInfo.HandleCount;
                info.VirtualSize    = processInfo.VirtualSize;
                info.WorkingSetSize = processInfo.WorkingSetSize;
            }
            catch
            {
            }

            try
            {
                info.FontName = WindowUtils.GetFontName(Handle);
            }
            catch
            {
            }

            try
            {
                var windowInfo = new WINDOW_INFO();
                windowInfo.cbSize = Marshal.SizeOf(windowInfo);
                if (User32.GetWindowInfo(Handle, ref windowInfo))
                {
                    info.WindowInfoExStyle = windowInfo.dwExStyle;
                }
            }
            catch
            {
            }

            try
            {
                uint key;
                Byte alpha;
                uint flags;
                var  result        = GetLayeredWindowAttributes(Handle, out key, out alpha, out flags);
                var  layeredWindow = (LayeredWindow)flags;
                info.LWA_ALPHA    = layeredWindow.HasFlag(LayeredWindow.LWA_ALPHA);
                info.LWA_COLORKEY = layeredWindow.HasFlag(LayeredWindow.LWA_COLORKEY);
            }
            catch
            {
            }

            try
            {
                info.Instance = process == null ? IntPtr.Zero : process.Modules[0].BaseAddress;
            }
            catch
            {
            }

            try
            {
                info.Parent = Path.GetFileName(process.GetParentProcess().GetMainModuleFileName());
            }
            catch
            {
            }

            try
            {
                var fileVersionInfo = process.MainModule.FileVersionInfo;
                info.ProductName    = fileVersionInfo.ProductName;
                info.ProductVersion = fileVersionInfo.ProductVersion;
                info.FileVersion    = fileVersionInfo.FileVersion;
                info.Copyright      = fileVersionInfo.LegalCopyright;
            }
            catch
            {
            }

            /*try
             * {
             *  var control = Control.FromHandle(Handle);
             *  var accessibilityObject = control.AccessibilityObject;
             *  info.AccessibleName = accessibilityObject == null ? "" : accessibilityObject.Name;
             *  info.AccessibleValue = accessibilityObject == null ? "" : accessibilityObject.Value;
             *  info.AccessibleRole = accessibilityObject == null ? "" : accessibilityObject.Role.ToString();
             *  info.AccessibleDescription = accessibilityObject == null ? "" : accessibilityObject.Description;
             * }
             * catch
             * {
             * }*/

            return(info);
        }