Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 8

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 3. Basics</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="index.html" title="Programming with gtkmm">
<link rel="prev" href="sec-packages-windows.html" title="Microsoft Windows">
<link rel="next" href="sec-headers-and-linking.html" title="Headers and Linking">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 3. Basics</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-packages-windows.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-headers-and-linking.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter" title="Chapter 3. Basics">
<div class="titlepage"><div><div><h2 class="title">
<a name="chapter-basics"></a>Chapter 3. Basics</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul>
<li><span class="sect1"><a href="chapter-basics.html#sec-basics-simple-example">Simple Example</a></span></li>
<li><span class="sect1"><a href="sec-headers-and-linking.html">Headers and Linking</a></span></li>
<li><span class="sect1"><a href="sec-widgets-overview.html">Widgets</a></span></li>
<li><span class="sect1"><a href="sec-signals-overview.html">Signals</a></span></li>
<li><span class="sect1"><a href="sec-basics-ustring.html">Glib::ustring</a></span></li>
<li><span class="sect1"><a href="sec-intermediate-types.html">Intermediate types</a></span></li>
<li><span class="sect1"><a href="sec-helloworld.html">Hello World in <span class="application">gtkmm</span></a></span></li>
</ul>
</div>
<p>
This chapter will introduce some of the most important aspects of <span class="application">gtkmm</span> coding. These will be demonstrated with simple working example code. However, this is just a taster, so you need to look at the other chapters for more substantial information.
</p>
<p>
Your existing knowledge of C++ will help you with <span class="application">gtkmm</span> as it would with any library. Unless we state otherwise, you can expect <span class="application">gtkmm</span> classes to behave like any other C++ class, and you can expect to use your existing C++ techniques with <span class="application">gtkmm</span> classes.
</p>
<div class="sect1" title="Simple Example">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-basics-simple-example"></a>Simple Example</h2></div></div></div>
<p>
To begin our introduction to <span class="application">gtkmm</span>, we'll start with the simplest
program possible. This program will create an empty 200 x 200 pixel window.
</p>
<p><a class="ulink" href="http://git.gnome.org/cgit/gtkmm-documentation/tree/examples/others/base" target="_top">Source Code</a></p>
<p>We will now explain each line of the example</p>
<pre class="programlisting">#include &lt;gtkmm.h&gt;</pre>
<p>
All <span class="application">gtkmm</span> programs must include certain <span class="application">gtkmm</span> headers; <code class="literal">gtkmm.h</code>
includes the entire <span class="application">gtkmm</span> kit. This is usually not a good idea, because
it includes a megabyte or so of headers, but for simple programs, it
suffices.
</p>
<p>
The next line:

</p>
<pre class="programlisting">Gtk::Main kit(argc, argv);</pre>
<p>

creates a <code class="classname">Gtk::Main</code> object.  This is needed in all <span class="application">gtkmm</span>
applications. The constructor for this object initializes <span class="application">gtkmm</span>,  and checks the
arguments passed to your application on the command line, looking for
standard options such as <code class="literal">-display</code>. It takes these from the argument list, leaving anything it does not
recognize for your application to parse or ignore.  This ensures
that all <span class="application">gtkmm</span> applications accept the same set of standard arguments.
</p>
<p>
The next two lines of code create and display a window:
</p>
<pre class="programlisting">Gtk::Window window;</pre>
<p>
The last line shows the window and enters the <span class="application">gtkmm</span> main processing loop, which will finish when the window is closed.
</p>
<pre class="programlisting">Gtk::Main::run(window);</pre>
<p>
After putting the source code in <code class="literal">simple.cc</code> you can compile the above program with gcc using:
</p>
<pre class="programlisting">g++ simple.cc -o simple `pkg-config gtkmm-2.4 --cflags --libs`</pre>
<p>
Note that you must surround
the <code class="literal">pkg-config</code> invocation with backquotes.
Backquotes cause the shell to execute the command inside them, and to use
the command's output as part of the command line.
</p>
</div>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-packages-windows.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-headers-and-linking.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Microsoft Windows </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Headers and Linking</td>
</tr>
</table>
</div>
</body>
</html>