예제 #1
0
        public void MakeMenu()
        {
            ObservableCollection<MenuItem> menuitems = new ObservableCollection<MenuItem>();
           
            foreach(xApp l in _applist.Distinct<xApp>())
            {
                
                xApp item = l;
                //Console.WriteLine("Loading app " + appslist.IndexOf(l) + " out of " + (appslist.Count - 1));
                Dispatcher.BeginInvoke((Action)(() =>
                {
                    //Console.WriteLine("This is not happening");

                    MenuItem s = new MenuItem(); s.Click += (object sender, RoutedEventArgs e) => { try { Process.Start(item.Path); } catch { MessageBox.Show("Unable to run item, make sure that the path is correct"); } }; s.Header = item.name; Image m = new Image(); var handle = item.icon.GetHbitmap();

                    try
                    {
                        m.Source = Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                        //Console.WriteLine("Image for " + l.name + " has been created");
                        s.Icon = m;
                    }
                    finally { InteropHelper.DeleteObject(handle); }
                   menuitems.Add(s);

                }));
            }
            Console.WriteLine(menuitems.Count);

            Dispatcher.Invoke(() =>menu.ItemsSource = menuitems);
        }
예제 #2
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;
 }
        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);
        }