|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="hello-world" xml:lang="pt-BR">
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title type="link">Hello World (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#examples"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2013-06-17" status="review"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Susanna Huhtanen</name>
|
|
Packit |
1470ea |
<email its:translate="no">ihmis.suski@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
<credit type="editor">
|
|
Packit |
1470ea |
<name>Tiffany Antopolski</name>
|
|
Packit |
1470ea |
<email its:translate="no">tiffany.antopolski@gmail.com</email>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
<credit type="editor">
|
|
Packit |
1470ea |
<name>Bastian Ilsø</name>
|
|
Packit |
1470ea |
<email its:translate="no">bastianilso@gnome.org</email>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>Creating a small "Hello, World" application using GTK+.</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Rafael Ferreira</mal:name>
|
|
Packit |
1470ea |
<mal:email>rafael.f.f1@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Hello world</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<note>
|
|
Packit |
1470ea |
For a detailed walk-through of creating a GTK+ dialog in C, see
|
|
Packit |
1470ea |
<link href="https://developer.gnome.org/gtk3/stable/gtk-getting-started.html">Getting Started with GTK+</link>
|
|
Packit |
1470ea |
</note>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
Writing a hello world GTK+ dialog in C can be done as seen in the code sample below:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication* app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *label;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
label = gtk_label_new ("Hello GNOME!");
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), label);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "Welcome to GNOME");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 200, 100);
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc,
|
|
Packit |
1470ea |
char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
GtkApplication initializes GTK+. It also connects the <gui>x</gui> button
|
|
Packit |
1470ea |
that's automatically generated along with the window to the "destroy" signal.
|
|
Packit |
1470ea |
We can start building our first window.
|
|
Packit |
1470ea |
We do this by creating a variable called window and assigning it
|
|
Packit |
1470ea |
a gtk_application_window_new. The window title can be any string you want it
|
|
Packit |
1470ea |
to be. To be on the safe side, it's best to stick to UTF-8 encoding.
|
|
Packit |
1470ea |
The code above will create a dialog window similar to what can be seen below:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/hello-world.png"/>
|
|
Packit |
1470ea |
</page>
|