GTK + graphical Application Development Learning notes

Source: Internet
Author: User
Tags gtk

Http://blog.chinaunix.net/u/22935/showart_305786.html
I. InitializationGTK +

WriteGTK +ProgramNeed to callGtk_initFunction pairGTK +Library Function initialization.

1.

Name::

Gtk_init

Function:

InitializationGTK +Library

Header file:

# Include <GTK/GTK. h>

Function prototype:

Void gtk_init (int * argc, char *** argv );

Parameters:

ArgcPointing to Main FunctionArgcPointer

ArgvPointing to Main FunctionArgvPointer

Return Value:

None

 

 

 

 When your program usesGTK +Before the tool library, you must initialize it.Gtk_initCan be initializedGTK +Tool library.Gtk_initTo the main function.Argc, argvPointer, it can change some does not meetGTK +The command line parameters required by the function.

BecauseGtk_initThe function does not return values. Therefore, if an error occurs during initialization, the program exits immediately.

2.

Name::

Gtk_init_check

Function:

InitializationGTK +Library

Header file:

# Include <GTK/GTK. h>

Function prototype:

Gboolean gtk_init_check (int * argc, char *** argv );

Parameters:

ArgcPointing to Main FunctionArgcPointer

ArgvPointing to Main FunctionArgvPointer

Return Value:

Return successfulTure, Error returnedFalse.

 

 

 

 There is anotherGTK +Library initialization FunctionGtk_init_check, Its role andGtk_initIdentical. The only difference is thatGtk_init_checkIf there is a return value, you can determine whether the initialization is successful.

 

2. Create a window

GTK +The component isGui. Windows, check boxes, buttons, and editing fields are all components. Usually, components and windows are defined as pointingGtkwidgetStructure pointer. InGTK +Medium,GtkwidgetIs a common data type used for all components and windows.

GTK +After the library is initialized, most applications create a main window. InGTK +The main window is often called a top-level window. The top-level window is not included in any other window, so it has no upper-level window. InGTK +The component has a parent-child relationship. The parent component is a container, and the child component is a component contained in the container. The top-level window does not have a parent window, but it may Become a container of other components.

InGTK +Build a component in two steps: Create a component and make it visible.Gtk_window_newThe function is responsible for creating a window.Gtk_widget_showThe function is responsible for making it visible.

2.

name : :

gtk_window_new

function :

Create a window

header file :

# include

function prototype :

gtkwidget * gtk_window_new (

parameter :

return value :

 

 

 

 

 

 

 

 

3.

name : :

gtk_widget_show

function :

display window

header file :

# include

function prototype :

gtk_widget_show (gtkwidget * window)

parameter :

return value :

 

 

 

 

 

 

 

 

 

III,GTK +Event Loop

PairGTK +After initializing and placing the window and component on the screen, the program callsGet_mainThe function waits for the execution of an event.

 

4.

Name::

Gtk_main

Function:

Wait for the occurrence of the event

Header file:

# Include <GTK/GTK. h>

Function prototype:

Void gtk_main (void );

Parameters:

None

Return Value:

None

 

 

 

 

Let's take a look at the procedure in Chapter 1. Maybe you will understand the functions above.

/* Base1.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_widget_show (window );

 Gtk_main ();

 Return false;

}

 

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

$./Base1

 

 

The program starts to define a form, and then uses the FunctionGtk_initInitializationGTK +Library. FunctionsGtk_window_newCreate a formGet_widget_showThis form is displayed. Program final callGtk_main ()Enter the main loop and wait for various events.

Note that the program cannot exit normally because the program does not have a call-back function. We will introduce the callback function below.

 

 

4. End the application

5.

name : :

gtk_main_quit

function :

end application

header file :

# include

function prototype :

void gtk_main_quit (void);

parameter :

none

return value :

none

Gtk_main_quitFunction can end the program It is usually called in the callback function. Next we will introduce the callback function.

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.