Beispiel #1
0
 //Got a new window
 public void Update(ProgramWindow value)
 {
     if (value.WindowTitle != null)
     {
         label_Title.Content = value.WindowTitle;
         btn_save.IsEnabled = true;
     }
 }
 public void Reset()
 {
     Window = null;
 }
        private void GlobalHookMouseDownExt(object sender, MouseEventExtArgs e)
        {
            //Get window from mouseclick point
            IntPtr windowHandle = WindowFromPoint(new InvokeStructs.POINT(e.X, e.Y));
            if (windowHandle == IntPtr.Zero) return;

            //Loop processes to find matching MainWindowHandle
            Process process = GetProcessFromHandle(windowHandle);
            if (process == null || process.MainWindowTitle == "WindowStay") return;

            //Get rectangle of found window
            try
            {
                InvokeStructs.RECT rect = GetWindowRectFromHandle(windowHandle);
                Window = new ProgramWindow(process.MainWindowTitle, rect);
                Notify();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception);
            }
        }
        public void SaveWindow(ProgramWindow window)
        {
            if (DoesWindowElementExist(window.WindowTitle))
            {
                UpdateWindowElement(window);

                //Find window we updated in list
                foreach (ProgramWindow item in _windows)
                {
                    if (item.WindowTitle == window.WindowTitle)
                    {
                        int index = _windows.IndexOf(item);
                        _windows[index] = window;
                    }
                }
            }
            else
            {
                AddWindowElement(window);
                _windows.Add(window);
            }
            Notify();
        }
        private void UpdateWindowElement(ProgramWindow window)
        {
            XElement el = new XElement("window");
            el.Add(new XAttribute("title", window.WindowTitle));
            el.Add(new XAttribute("top", window.WindowRect.Top));
            el.Add(new XAttribute("right", window.WindowRect.Right));
            el.Add(new XAttribute("bottom", window.WindowRect.Bottom));
            el.Add(new XAttribute("left", window.WindowRect.Left));

            XmlController.Instance.UpdateWindowElementOnAttributeNameAndValue("title", window.WindowTitle, el);
        }