예제 #1
0
        void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
        {
            Debug.Print("Creating window...");

            OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out WinHandle);

            API.CheckReturn(err);
            Debug.Print("Created window " + WinHandle.ToString());

            IntPtr titleCF = CF.CFSTR(title);

            Debug.Print("Setting window title: {0},   CFstring : {1},  Text : {2}", WinHandle, titleCF, title);
            API.SetWindowTitleWithCFString(WinHandle, titleCF);

            SetLocation(r.X, r.Y);
            SetSize(r.Width, r.Height);
            LoadSize();

            Rect titleSize = API.GetWindowBounds(WinHandle, WindowRegionCode.TitleBarRegion);

            mTitlebarHeight = titleSize.Height;
            Debug.Print("Titlebar size: {0}", titleSize);
            ConnectEvents();
            Debug.Print("Attached window events.");
        }
예제 #2
0
        public TaskItem(WinHandle WinProcess, DLib.Base.Settings s)
        {
            InitializeComponent();
            thisproc = WinProcess;
            ImageBrush b = new ImageBrush();

            try
            {
                if (WinProcess.WindowIcon != null)
                {
                    m = WinProcess.WindowIcon.ToBitmap();
                    var d = Imaging.CreateBitmapSourceFromHBitmap(m.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                    b.ImageSource    = d;
                    TaskImage.Source = b.ImageSource;
                }
                WinProcess.TitleChanged += WinProcess_TitleChanged;
            }
            catch (Exception ex)
            {
            }
            TaskText.Content = WinProcess.Title;

            double height = s.WindowHeight;

            TaskText.Margin  = new Thickness(height, 0, 0, 0);
            TaskImage.Width  = height;
            TaskImage.Height = height;
            Height           = height;

            DLib.WPF.StyleWPFLabel(TaskText, s);
        }
예제 #3
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)
        {
            var g = new GUIItem();

            Application.Current.Dispatcher.Invoke(() => {
                TaskItem tsk = new TaskItem(window, taskItemHeight);
                Tasks.Children.Add(tsk);
                g.Destroy = () => { Application.Current.Dispatcher.Invoke(() => Tasks.Children.Remove(tsk)); };
            });
            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);
        }