How to embed a program inside another using GTK, XLib or any similar?

雨燕双飞 提交于 2019-12-08 13:11:18

问题


I'm trying to make a "simple" program, all it does is to list all opened programs and, once you choose one, it opens it inside your window (like a thumbnail you may say, but you can also interact).

One thing, it has to be one way only (I can't alter the embbeded program and add a "socket" or "plug" for instance). I want to be able to embbed any program (e.g. Opera, evince, JDownloader etc).

Does anyone have any idea of how can I do it?

If it can't be done using GTK, can it be done using X or any similar? How?


回答1:


It appears that you're looking for something like XEmbed. A good tutorial in python and gtk is at http://www.moeraki.com/pygtktutorial/pygtk2tutorial/sec-PlugsAndSockets.html




回答2:


You can use GtkPlug and GtkSocket for that.




回答3:


using System;using Gtk;using System.Runtime.InteropServices;       public partial class MainWindow : Gtk.Window{



public MainWindow () : base(Gtk.WindowType.Toplevel)
{
    Gtk.Socket socket;
    int xid;
    Fixed fixed2=new Fixed();
    this.socket = new Socket();
    this.socket.WidthRequest = 500;
    this.socket.HeightRequest = 500;
    this.socket.Visible = true;
    this.socket.Realized += new EventHandler(OnVideoWidgetRealized);

    fixed2.Put(socket, 0, 0);
    fixed2.SetSizeRequest(500,500);
    this.Add(fixed2);
    this.ShowAll();

    OnButton17Clicked();

}

protected virtual void OnVideoWidgetRealized (object sender, EventArgs
                                              args)
{
    this.xid = (int)socket.Id;
    Console.WriteLine("this.xid:"+this.xid);
}

protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
    Application.Quit ();
    a.RetVal = true;
    this.socket = new Socket();
}

protected  void OnButton17Clicked ()
{
    var paramString = string.Format("-wid {0} 1.avi", xid);
    System.Diagnostics.Process proc = new System.Diagnostics.Process();
    proc.StartInfo.FileName = "mplayer.exe";
    proc.StartInfo.Arguments = paramString;
    proc.Start();
    proc.WaitForExit();

}
public static void Main()
{
    Application.Init();
    new MainWindow();
    Application.Run();
}}


来源:https://stackoverflow.com/questions/6771719/how-to-embed-a-program-inside-another-using-gtk-xlib-or-any-similar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!