[Gtk-sharp-list] Gtk-Window only declared in a DLL and start with console

Peter Johanson latexer@gentoo.org
Thu, 20 Jan 2005 10:56:17 -0800


On Thu, Jan 20, 2005 at 07:45:49PM +0100, Thomas Z?hlke wrote:
> Hi,
> 
> i try to write a console program, that can later start a gtk window. the 
> console should not use any other dlls than the one that declares the window.

I've started doing this for a Go game i've been (re)writing. The key was
to make the main "Gui" class have it's own thread, and have
implementations of a "Gui" add the necessary foo in the Run() that is
used when the thread runs. Here's a snippet from my GtkGui.cs:
      protected override void Work()                                  
      {                                                               
              Application.Run();                                      
      }                                                               
                                                                      
      public override bool Init()                                     
      {                                                               
              Application.Init();                                     
              Window win = new Window ("Testing!");                   
              Button button = new Button("Push Me!");                 
                                                                      
              win.DeleteEvent  +=                                     
                      new DeleteEventHandler (OnWindowDelete);        
              button.Clicked +=                                       
                      new EventHandler(OnClicked);                    
              win.Add(button);                                        
              win.ShowAll();                                          
                                                                      
              return true;                                            
      }
</snip>

Work() overrides the virtual function that is called when the thread is
started. That way my console/spawning program uses Reflection to load
the dll, instantiate the class, and then kick it off. There may be other
ways to do this without creating a seperate thread for the loaded GUI.

HTH,

-pete

> 
> The gtk_window.dll file contains only:
> using System;
> using Gtk;
> using Gdk;
> namespace gtk_window{
>    public class mywindow{
>        public Gtk.Window win;
>        public fenster(){
>            win = new Gtk.Window("gtk_test4");
>            win.SetDefaultSize(800, 600);
>            win.DeleteEvent += OnWinDelete;
>            win.ShowAll();
>        }
> 
>        void OnWinDelete(object o, DeleteEventArgs args) {
>            Application.Quit();
>        }
>    }
> }
> 
> and in the main program i try:
> using gtk_window;
> ...
>        private mywindow mw;
>        mw = new mywindow();
> ...
> 
> but durin running this program, it terminates with an error at the 
> second line.
> 
> i can solve the problem when i tell the main program (the console 
> program) that it should use gtk-sharp.dll... and i'm writing:
> Application.Init();
> mw = new mywindow();
> Application.Run();
> 
> but i think it must be possible to generate a window, only out of the 
> dll, because i will try to use Windows.Form or wxNET later, only by 
> replacing the gtk_window.dll.
> 
> hope for solutions ;-)
> Thomas Z?hlke
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 

-- 
Peter Johanson
<latexer@gentoo.org>