Haha under Ubuntu! GTK +!

Source: Internet
Author: User
Tags cairo gtk types of functions
Since GTK is basically written in the C language, you must have a C compiler. After installing Ubuntu, you will have GCC, however, the necessary header file is missing. In text mode, you can install the Security build-essential suite, for example:

Sudo apt-Get install build-essential

After the installation is complete, you can set a basic C statement:

  • Hello. c

# Include <stdio. h>

Int main (void ){
Printf ("Hello! World! /N ");
Printf ("haha! C! /N ");
Return 0;
}


Let's take a look at the following:

$ Gcc-O hello. c
$./Hello
Hello! World!
Haha! C!


Next, install the GTK Development Kit libgtk2.0-Dev:

Sudo apt-Get install libgtk2.0-Dev


After installing GTK, you can use PKG-config to view the GTK-related environment information:

PKG-config -- cflags -- libs GTK ++-2.0


PKG-config will retrieve the GTK attachment. PC users to obtain the relevant response information. -- cflags will list include objects, -- libs will list the corresponding response and its contents, take my computer as an example:

$ PKG-config -- cflags -- libs GTK ++-2.0
-I/usr/include/gtk-2.0-I/usr/lib/gtk-2.0/include-I/usr/include/atk-1.0-I/usr/include/Cairo-I/usr/include /pango-1.0-I/usr/include/glib-2.0-I/usr/lib/glib-2.0/include-I/usr/include/FreeType2-I/usr/include/libpng12 -I/usr/include/pixman-1-lgtk-x11-2.0-lgdk-x11-2.0-latk-1.0-lm-lgdk_pixbuf-2.0-lpangocairo-1.0-lcairo-lpango-1.0-LDL-lgobject-2.0


The split-line operation is clearer than the split-line operation. For example:

$ PKG-config -- cflags GTK ++-2.0
-I/usr/include/gtk-2.0-I/usr/lib/gtk-2.0/include-I/usr/include/atk-1.0-I/usr/include/Cairo-I/usr/include /pango-1.0-I/usr/include/glib-2.0-I/usr/lib/glib-2.0/include-I/usr/include/FreeType2-I/usr/include/libpng12 -I/usr/include/pixman-1
$ PKG-config -- libs GTK ++-2.0
-Lgtk-x11-2.0-lgdk-x11-2.0-latk-1.0-lgdk_pixbuf-2.0-lm-lpangocairo-1.0-lpango-1.0-lcairo-lgobject-2.0-lgmodule-2.0-LDL-lglib-2.0


The resulting form contains the following ):

  • GTK (-lgtk): a widget-based handler for gdk.
  • Gdk (-lgdk): xlib package Runtime (wrapper )..
  • Gdk-pixbuf (-lgdk_pixbuf): image processing function.
  • Pango (-lpango): A Chinese simplified text.
  • Gobject (-lgobject): the type of train used by GTK as the basis.
  • Gmodule.
  • Glib (-lglib): includes various types of functions. GTK is based on glib, so you need this function.
  • Xlib (-lx11): used by gdk.
  • Xext (-lxext): includes the shared memory pixmaps (shared memory pixmaps) and other X-forwarded interfaces.
  • Math (-lm): the mathematical formula used by GTK for various purposes.

It is not vulgar to say that, starting from the most simple basic window production, the title of the window is "Haha! GTK + !」 Okay. Use any of the plug-ins to compile a hellogtk. C case. The content is as follows:

  • Hellogtk. c
# Include <GTK/GTK. h>

Int main (INT argc, char * argv []) {
Gtkwidget * window;

Gtk_init (& argc, & argv );
Window = gtk_window_new (gtk_window_toplevel );
Gtk_window_set_title (gtk_window (window), "haha! GTK +! ");
Gtk_widget_show (window );
Gtk_main ();

Return 0;
}


First include the necessary GTK header case, and then see the gtk_init (). This function will initialize the function and set the setting mechanism, GTK has the opportunity to handle the number of command columns that the program calls. GTK checks whether the following arguments are available and handles them:

  • -GTK-Module
  • -G-fatal-Warnings
  • -GTK-Debug
  • -GTK-no-Debug
  • -Gdk-Debug
  • -Gdk-no-Debug
  • -Display
  • -Sync
  • -Name
  • -Class


These values will be removed from the index column, and the rest will be processed by your program.

Although GTK uses C to Create a token, it can pass through the gobject function to support the token and intent reading of objects, through the huge collection, you can also support multi-type reading. The following figure shows how to configure a GTK object:
Gobject
+ -- Ginitiallyunowned
+ -- Gtkobject
+ -- Gtkwidget
+ -- Gtkcontainer
+ -- Gtkbin
+ -- Gtkwindow

Gtk_window_new () creates a gtkwindow, which is a basic window object. gtkwindow refers to gtkbin, gtkbin refers to gtkcontainer, and gtkcontainer can accommodate other widgets, therefore, other widgets can be placed in the gtkwindow, and they are all post-generations of the gtkwidget.

In the component of the correspondence handler, In the GTK + operator, if you want to check the relation between the operator and the function set by gtkwindow, that is, the function name of the function starting with gtk_window, directly query the description file of the parameter gtkwindow.

In the example, you use gtk_window_new () to generate a gtkwindow in the memory (but it is not actually displayed on the screen ), the metric data is set to gtkwindowtype. There are two available settings:

  • Gtk_window_toplevel: an out-of-box standard GTK window.
  • Gtk_window_popup: a pop-up window, such as a speaker, pop-up list, or prompt text.


To set the gtkwindow standard text, use the gtk_window_set_title (). The gtk_window giant set is used to convert the window object struct type to the gtkwindow struct type.

Gtk_window_new () is only used to generate a gtkwindow in the memory. to display the GTK widget on the screen, use gtk_widget_show (), finally, call gtk_main (). This will give the program's Control Right to GTK, and GTK will wait for events such as failover, billing, and Case Io notifications.

You can use the following commands to import and export rows:

$ GCC hellogtk. C-o hellogtk 'pkg-config -- cflags -- libs GTK +-1000'
$./Hellogtk


PKG-config will first obtain the GTK header's position and correspondence information, and then provide it to GCC for further debugging. The following figure shows the line of a program:

As a result, gtk_main () will grant the control permission to GTK and will not return until it calls gtk_main_quit, this example has not been implemented yet (and will introduce how to implement it later ), therefore, pressing the top-right X button in this window does not really matter, but you must first use the CTRL + C compiler program in text mode.

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.