Exemplo n.º 1
0
        private SystemListView GetDesktopListView()
        {
            SystemWindow[] sws = SystemWindow.FilterToplevelWindows(delegate(SystemWindow sw)
            {
                return(sw.ClassName == "Progman" && sw.Title == "Program Manager" && sw.Process.ProcessName == "explorer");
            });
            if (sws.Length != 1)
            {
                MessageBox.Show("Could not find Desktop window");
                return(null);
            }
            sws = sws[0].FilterDescendantWindows(false, delegate(SystemWindow sw)
            {
                return(sw.ClassName == "SysListView32" && sw.Title == "FolderView");
            });
            if (sws.Length != 1)
            {
                MessageBox.Show("Could not find Desktop window");
                return(null);
            }
            SystemListView slv = SystemListView.FromSystemWindow(sws[0]);

            if (slv == null)
            {
                MessageBox.Show("No desktop icons found");
            }
            return(slv);
        }
 static void Main(string[] args)
 {
     // Create a SystemWindow object from the HWND of the ListView
     SystemWindow lvWindow = new SystemWindow((IntPtr)0x6d1d38);
     // Create a ListView object from the SystemWindow object
     var lv = SystemListView.FromSystemWindow(lvWindow);
     // Read text from a row
     var text = lv[0].Title;
 }
        public static SystemListView GetSystemListView(SystemWindow systemWindow)
        {
            var systemListView = SystemListView.FromSystemWindow(systemWindow);

            if (systemListView == null)
            {
                Log.WriteLine("There were no desktop icons.");
            }

            return(systemListView);
        }
Exemplo n.º 4
0
        public void Add(string _hwnd)
        {
            IntPtr hwnd = (IntPtr)Convert.ToInt32(_hwnd, 16);

            lvWindow = new SystemWindow(hwnd);
            lv       = SystemListView.FromSystemWindow(lvWindow);

            MyHook           = new Hook(HookType.WH_CALLWNDPROC, false, false);
            MyHook.Callback += MyHookCallback;
            MyHook.StartHook();
        }
Exemplo n.º 5
0
        internal override WindowContent ParseContent(SystemWindow sw)
        {
            uint LVM_GETITEMCOUNT = (0x1000 + 4);
            int  cnt = sw.SendGetMessage(LVM_GETITEMCOUNT);

            if (cnt == 0 && sw.ClassName != "SysListView32")
            {
                throw new Exception();
            }
            try
            {
                SystemListView slv = SystemListView.FromSystemWindow(sw);
                // are there column headers?
                string[] hdr = null;
                SystemListViewColumn[] columns = slv.Columns;
                if (columns.Length > 0)
                {
                    hdr = new string[columns.Length];
                    for (int i = 0; i < hdr.Length; i++)
                    {
                        hdr[i] = columns[i].Title;
                    }
                }
                int           itemCount = slv.Count;
                List <string> values    = new List <string>();
                for (int i = 0; i < itemCount; i++)
                {
                    SystemListViewItem item = slv[i];
                    string             name = item.Title;
                    if (hdr != null)
                    {
                        for (int j = 1; j < hdr.Length; j++)
                        {
                            SystemListViewItem subitem = slv[i, j];
                            name += "\t" + subitem.Title;
                        }
                    }
                    values.Add(name);
                }
                if (hdr != null)
                {
                    string lines = "", headers = "";
                    foreach (string h in hdr)
                    {
                        if (lines.Length > 0)
                        {
                            lines += "\t";
                        }
                        if (headers.Length > 0)
                        {
                            headers += "\t";
                        }
                        headers += h;
                        lines   += ListContent.Repeat('~', h.Length);
                    }
                    values.Insert(0, lines);
                    values.Insert(0, headers);
                    return(new ListContent("DetailsListView", -1, null, values.ToArray()));
                }
                else
                {
                    return(new ListContent("ListView", -1, null, values.ToArray()));
                }
            }
            catch
            {
                // fallback to slower accessible object method
            }
            SystemAccessibleObject o = SystemAccessibleObject.FromWindow(sw, AccessibleObjectID.OBJID_CLIENT);

            if (o.RoleIndex == 33)
            {
                // are there column headers?
                int      cs  = o.Children.Length;
                string[] hdr = null;
                if (cs > 0)
                {
                    SystemAccessibleObject headers = o.Children[cs - 1];
                    if (headers.RoleIndex == 9 && headers.Window != sw)
                    {
                        SystemAccessibleObject hdrL = SystemAccessibleObject.FromWindow(headers.Window, AccessibleObjectID.OBJID_CLIENT);
                        hdr = new string[hdrL.Children.Length];
                        for (int i = 0; i < hdr.Length; i++)
                        {
                            if (hdrL.Children[i].RoleIndex != 25)
                            {
                                hdr = null;
                                break;
                            }
                            hdr[i] = hdrL.Children[i].Name;
                        }
                        if (hdr != null)
                        {
                            cs--;
                        }
                    }
                }
                List <string> values = new List <string>();
                for (int i = 0; i < cs; i++)
                {
                    if (o.Children[i].RoleIndex == 34)
                    {
                        string name = o.Children[i].Name;
                        if (hdr != null)
                        {
                            try
                            {
                                string cols = o.Children[i].Description;
                                if (cols == null && values.Count == 0)
                                {
                                    hdr = null;
                                }
                                else
                                {
                                    string        tmpCols = "; " + cols;
                                    List <string> usedHdr = new List <string>();
                                    foreach (string header in hdr)
                                    {
                                        string h = "; " + header + ": ";
                                        if (tmpCols.Contains(h))
                                        {
                                            usedHdr.Add(header);
                                            tmpCols = tmpCols.Substring(tmpCols.IndexOf(h) + h.Length);
                                        }
                                    }
                                    foreach (string header in hdr)
                                    {
                                        name += "\t";
                                        if (usedHdr.Count > 0 && usedHdr[0] == header)
                                        {
                                            if (!cols.StartsWith(header + ": "))
                                            {
                                                throw new Exception();
                                            }
                                            cols = cols.Substring(header.Length + 1);
                                            string elem;
                                            if (usedHdr.Count > 1)
                                            {
                                                int pos = cols.IndexOf("; " + usedHdr[1] + ": ");
                                                elem = cols.Substring(0, pos);
                                                cols = cols.Substring(pos + 2);
                                            }
                                            else
                                            {
                                                elem = cols;
                                                cols = "";
                                            }
                                            name += elem;
                                            usedHdr.RemoveAt(0);
                                        }
                                    }
                                }
                            }
                            catch (COMException ex)
                            {
                                if (ex.ErrorCode == -2147352573 && values.Count == 0)
                                {
                                    hdr = null;
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                        }
                        values.Add(name);
                    }
                }
                if (hdr != null)
                {
                    string lines = "", headers = "";
                    foreach (string h in hdr)
                    {
                        if (lines.Length > 0)
                        {
                            lines += "\t";
                        }
                        if (headers.Length > 0)
                        {
                            headers += "\t";
                        }
                        headers += h;
                        lines   += ListContent.Repeat('~', h.Length);
                    }
                    values.Insert(0, lines);
                    values.Insert(0, headers);
                    return(new ListContent("DetailsListView", -1, null, values.ToArray()));
                }
                else
                {
                    return(new ListContent("ListView", -1, null, values.ToArray()));
                }
            }
            else
            {
                return(new ListContent("EmptyListView", -1, null, new string[0]));
            }
        }