Exemplo n.º 1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            _info = new WindowSaveInfo();
            _info.ForegroundWindow = WinAPI.GetCurrentWindow();
            List <IntPtr> lst = WinAPI.GetAllWindows();
            Graph         g   = new Graph();

            foreach (IntPtr hWnd in lst)
            {
                WindowPosition wp = WindowPosition.FromHandle(hWnd);
                _info.WindowSave.Add(hWnd, wp);
                g.AddEdge(hWnd, wp.NextWindow);
            }
            _info.IterOrder = g.ToplogicalSort().Select(x => x.Handle).Reverse().ToList();
            this.btnWriteToFile.IsEnabled = true;
            this.btnLoad.IsEnabled        = true;
            this.txtCurrent.Text          = "User Save @ " + DateTime.Now;
            if (this.chkAutoSave.IsChecked.HasValue && this.chkAutoSave.IsChecked.Value)
            {
                if (!Directory.Exists(AUTOSAVE_DIR))
                {
                    Directory.CreateDirectory(AUTOSAVE_DIR);
                }
                string timeStr  = DateTime.Now.ToString("yyyyMMddhhmmssfff");
                string filename = Path.Combine(AUTOSAVE_DIR, timeStr + ".wsi");
                _info.Save(filename);
            }
        }
Exemplo n.º 2
0
        private void btnLoadFromFile_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog()
            {
                Title  = "Load Window Info",
                Filter = "Window Save Info|*.wsi"
            };
            bool?result = ofd.ShowDialog();

            if (result.HasValue && result.Value)
            {
                string file = ofd.FileName;
                this.txtCurrent.Text          = file;
                this.btnLoad.IsEnabled        = true;
                this.btnWriteToFile.IsEnabled = true;
                _info = WindowSaveInfo.FromFile(file);
            }
        }