Exemple #1
0
 private GUIItem AddNewTaskItem(WinHandle window)
 {
     window.TitleChanged += Window_TitleChanged;
     var g = new GUIItem();
     Application.Current.Dispatcher.Invoke(() => {
         try
         {
             MenuItem s = new MenuItem();
             s.Click += (object sender, RoutedEventArgs e) => { window.MaximizeMinimize(); };
             s.Header = window.Title;
             s.Tag = window.Ptr.ToString();
             Image m = new Image();
             var handle = window.WindowIcon.ToBitmap().GetHbitmap();
             try
             {
                 m.Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                 s.Icon = m;
             }
             finally { InteropHelper.DeleteObject(handle); }
             g.Destroy = () => { Application.Current.Dispatcher.Invoke(() => ProcMenu.Items.Remove(ProcMenu.Items.Cast<MenuItem>().Where(x => x.Tag == s.Tag).First())); };
             ProcMenu.Items.Add(s);
         }
         catch { }
     });
     return g;
 }
Exemple #2
0
 private void TaskClicked(object sender, MouseButtonEventArgs e)
 {
     thisproc.MaximizeMinimize();
 }
        private GUIItem AddNewTaskItem(WinHandle window)
        {
            //window.TitleChanged += Window_TitleChanged;
            var g = new GUIItem();

            Application.Current.Dispatcher.Invoke(() =>
            {
                try
                {
                    StackPanel s       = new StackPanel();
                    ListBoxItem holder = new ListBoxItem();
                    holder.Focusable   = false;
                    s.Tag = window.Ptr.ToString();

                    holder.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) =>
                    {
                        RefreshTasks();
                        window.MaximizeMinimize();
                    };
                    ContextMenu o = new ContextMenu();
                    var h         = new MenuItem()
                    {
                        Header = "Close"
                    };
                    h.Click += (object sender, RoutedEventArgs e) => { InteropHelper.CloseWindow((IntPtr)int.Parse(s.Tag.ToString())); };
                    o.Items.Add(h);
                    s.ContextMenu = o;
                    Label l       = new Label();
                    l.Content     = window.Title;
                    s.Width       = 60;
                    l.Foreground  = new SolidColorBrush(Colors.White);
                    l.FontSize    = 10;
                    Image m       = new Image();
                    var handle    = window.WindowIcon.ToBitmap().GetHbitmap();
                    try
                    {
                        m.Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        m.Width  = 25;
                        m.Height = 25;
                        s.Children.Add(m);
                    }
                    finally { InteropHelper.DeleteObject(handle); }
                    s.Children.Add(l);
                    s.Height       = 60;
                    g.Destroy      = () => { Application.Current.Dispatcher.Invoke(() => { Left += s.Width; ProcMenu.Width -= s.Width; ProcMenu.Items.Remove(ProcMenu.Items.OfType <ListBoxItem>().Where(x => x.Tag == s.Tag).First()); }); };
                    holder.Content = s;
                    RefreshTasks();
                    ProcMenu.Items.Add(holder);
                    Console.WriteLine("Added");
                    ProcMenu.Width += s.Width;
                    Left           -= s.Width;
                    Width           = ProcMenu.Width;
                }
                catch
                (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            });
            return(g);
        }