Helloworld of GTK + Learning

Source: Internet
Author: User
Tags gtk

PKG-config -- Libs -- cflags GTK ++-2.0

PKG-config -- version // view the version number of PKG-config

PKG-config -- modversion GTK + // view the version number of gtk1.0

PKG-config -- modversion GTK +-2.0 // view the version number of gtk2.0

# Include <GTK/GTK. h> contains all the required header files in GTK + programming, and also contains gdk. H and glib. h. If you want to use gnome components and library functions, including gnome. H.

Gtk_init (& argc, & argv)
Call gtk_init (Gint * argc, gchar *** argv)
Set some default values for us, such as visual and color ing, and then call gdk_init (Gint * argc, gchar *** argv). This function initializes the function library and sets the default signal processing function, and check whether the command line is passed to the application.Program.
You can search for the values listed below.
-- GTK-Module
G-fata1-warnings
-- GTK-Debug
-- GTK-no-Debug
-- Gdk-Debug
-- Gdk-no-Debug
-- Display
-- Sync
-- No-xshm
-- Name
-- Class
It deletes the preceding parameters from the variable table and separates all unrecognized values. The application can analyze or ignore these values, thus claiming some standard parameters acceptable to GTK applications.
The following two lines create and display a window:
Window = gtk_window_new (gtk_window_toplevel );
Gtk_widget_show (window );
The gtk_window_toplevel parameter specifies that the window uses the status settings and location settings specified by the window management program.

Gtk_main ();
Is the function to be called by each GTK application. When the program runs here, GTK enters the waiting state, waiting for X events, timeout, or file input/output

# Include < GTK / GTK. h > Including all required header files in GTK + programming, including gdk. h and glib. h.
If you want to use gnome components and library functions, including gnome. H, you can

Gtk_init ( & Argc, & Argv)
Call gtk_init (Gint * Argc, gchar *** Argv)
Set some default values for us, such as visual and color ing, and then call gdk_init (Gint * Argc, gchar *** Argv), this function initializes the function library, sets the default signal processing function, and checks the parameters passed to the application through the command line.
You can search for the values listed below.
-- GTK - Module
-- G - Fata1 - Warnings
-- GTK - Debug
-- GTK - No - Debug
-- Gdk - Debug
-- Gdk - No - Debug
-- Display
-- Sync
-- No - Xshm
-- Name
-- Class
It deletes the preceding parameters from the variable table and separates all unrecognized values. The application can analyze or ignore these values, thus claiming some standard parameters acceptable to GTK applications.
The following two lines create and display a window:
Window = Gtk_window_new (gtk_window_toplevel );
Gtk_widget_show (window );
The gtk_window_toplevel parameter specifies that the window uses the status settings and location settings specified by the window management program.

Gtk_main ();
Is the function to be called by each GTK application. When the program runs here, GTK enters the waiting state, waiting for X events, timeout, or file input/output

/*Helloword. c*/

# Include<GTK/GTK. h>
VoidHello (gtkwidget*Widget, gpointer data)
{
G_print ("Hello world! \ N");
}

Gint delete_event (gtkwidget*Widget, gdkevent*Event, Gpointer data)
{
G_print ("Delete event occurrend \ n");
 Return(True );
}

VoidDestroy (gtkwidget*Widget, gpointer data)
{
Gtk_main_quit ();
}

Int Main ( Int Argc, Char   * Argv [])
{
Gtkwidget * Window;
Gtkwidget * Button;
Gtk_init ( & Argc, & Argv );
Window = Gtk_window_new (gtk_window_toplevel );
G_signal_connect (g_object (window ), " Delete_event " , G_callback (delete_event), null );

G_signal_connect (g_object (window ), " Destory " , G_callback (destroy), null );
Gtk_container_set_border_width (gtk_container (window ), 10 );
Button = Gtk_button_new_with_label ( " Hello World " ); G_signal_connect_swapped (g_object (button ), " Clicked " , G_callback (Hello), null );
G_signal_connect (g_object (button ), " Clicked " , G_callback (Hello), null );
G_signal_connect_swapped (gtk_object (button ), " Clicked " , G_callback (gtk_widget_destroy), window );
 
Gtk_container_add (gtk_container (window), button );
Gtk_widget_show (button );
Gtk_widget_show (window );
Gtk_main ();
  Return ( 0 );
}
 

Gcc-O helloword. c 'pkg-Config--Cflags--Libs GTK+-2.0`

Gcc-O helloword. c 'pkg-config -- cflags -- libs GTK +-1000'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.