Re: How to put GTK into a C function?



On Thursday 05 September 2002 08:58, Mullin Yu wrote:

The call to gtk_init is only needed once, at the top of the program (in main).
Once that's been done, you should call gtk_main (from main).  This sets up 
the library and takes control of your program's flow of execution, and calls 
your code as and when needed.

Once gtk_main is running, all you should need to do is call gtk_window_new 
and gtk_window_show to create new windows.  But you might want to have a look 
at gtk_dialog_run as well, plus the documentation for the "Main loop and 
events" in the GTK+ docs for a more general overview.

Good luck
Dave

> > Hi all,
>
> I saw from the tutorial that we can write a simple GTK application like the
> following:
>
> #include <gtk/gtk.h>
>
> int main( int   argc,
>           char *argv[] )
> {
>     GtkWidget *window;
>
>     gtk_init (&argc, &argv);
>
>     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     gtk_widget_show  (window);
>
>     gtk_main ();
>
>     return 0;
> }
>
> But now, I want to put it inside a function that will call to pop up a
> window. What should I do? What should I need to pass as argc and argv[]?
>
> .......
> .......
>
> function test()
> {
>     // some logic are here
>     //
>     //
>
>     int returnCode;
>
>     returnCode = openDialog(NULL, NULL);
>
> }
>
>
> int openDialog( int   argc,
>           char *argv[] )
> {
>     GtkWidget *window;
>
>     gtk_init (&argc, &argv);
>
>     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     gtk_widget_show  (window);
>
>     gtk_main ();
>
>     return 0;
> }
>
> Thanks!
>
> Best regards,
> Mullin

----------------------------------------
Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1"
Content-Transfer-Encoding: quoted-printable
Content-Description: 
----------------------------------------



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]