Esempio n. 1
0
        private void RestoreIcons(string xmlPath)
        {
            this.Icon = Properties.Resources.hello_;

            List <IconItem> icons = GetIcons();

            if (!System.IO.File.Exists(xmlPath))
            {
                MessageBox.Show("配置文件[" + xmlPath + "]不存在!先保存图标设置!");
                return;
            }

            // 读取XML文件,转化为集合
            XElement root = XElement.Load(xmlPath);
            IEnumerable <XElement> nodes = root.Elements();

            if (nodes != null && nodes.Count() > 0)
            {
                foreach (var node in nodes)
                {
                    String iconText  = node.Attribute("text").Value;
                    Int32  locationX = Int32.Parse(node.Attribute("x").Value);
                    Int32  locationY = Int32.Parse(node.Attribute("y").Value);

                    // 检查图标是否存在,存在则设置位置,不存在就跳过
                    IconItem tmpIcon = icons.FirstOrDefault(x => x.Text == iconText);
                    if (tmpIcon != null)
                    {
                        m_Desktop.SetItemLocation(tmpIcon.Index, new Point(locationX, locationY));
                    }
                }
            }

            lblState.Text = "恢复完成!";
        }
Esempio n. 2
0
        private List <IconItem> GetIcons()
        {
            List <IconItem> icons = new List <IconItem>();

            this.Icon = Properties.Resources.friendly_icons;

            // 获取图标数量,遍历获取文本与坐标
            WriteConsole("桌面ListView句柄:" + m_Desktop.DesktopListViewPtr.ToString());
            WriteConsole("桌面进程ID:" + m_Desktop.DesktopProcessID);
            WriteConsole("侦测到桌面图标数:" + m_Desktop.GetItemsCount());
            Int32 iconsCount = m_Desktop.GetItemsCount();

            for (Int32 i = 0; i < iconsCount; i++)
            {
                IconItem tmpIcon = new IconItem();
                tmpIcon.Text     = m_Desktop.GetItemText(i);
                tmpIcon.Location = m_Desktop.GetItemLocation(i);
                tmpIcon.Index    = i;
                icons.Add(tmpIcon);
            }
            return(icons);
        }