Getting
started with winGTK
and wGLADE
By Barry Drake
To setup and use wGlade with winGTK:
- Download winGTK & wGLADE packages from wingtk.sourceforge.net
and install them.
- Click on Start > Programs > Accessories > Notepad
. Open the file: C:\autoexec.bat. Add this line at the
end of the file:
SET PATH = %PATH%;C:\winGTK
- Save the file and close notepad
Note that the procedure for using Glade is the same if you have chosen
GTK4Win or Dev-C++ with DevEx. The remainder of the procedure with
GTK4Win is explained in the included documentaion, and if you choose Dev-C++
you simply make use of the GTK+ template, and add your C source files to
the project you have created!
Creating & running a project:
- Open wGLADE from the desktop icon.
- Now design your interface. First you must, add
a window. To do this, click on the top left of the icons. This window
is the basis of all designs. Then you must add a container. The
container can be of several different types.
For this exercise, add a 'Fixed Container' from the Palette window
onto your window. This is the one on the eighth row down in the right
hand column. It has a popup hint that says "Fixed Positions". Then
add two buttons to this container. Choose the button labelled OK. The buttons
can be re-positioned and resized - why not make them fairly large. Your
project will now have two buttons labelled 'Button 1' and 'Button 2'.
|
Click on Button 1. If you look at the 'Properties' window, you
will see that it now refers to Button 1. Change the Button
Text field to read 'Exit'. Now click on the 'Signals' tab
in the properties window. You will see that this is empty.
Use the dropdown to select 'Clicked' as the signal, and use
the dropdown under 'Handler' to select gtk_main_quit. Click
on the 'Add' button. Now repeat the process for button 2,
calling the button 'Click-Me'. Set the signal to 'Clicked' once
more, but this time leave the signal handler set to the default that
is offered.
This will read 'on_button2_clicked'.
Now click the Window icon in the Glade main window. This is
the object labelled 'window1'. The properties window should now bear
the heading 'window1'. Change the Title to: 'My First Program'. This
is going to be your Window title for the compiled executable. Now
set up the signal for your main window. You need to set the signal
to 'destroy' and the handler to gtk_main_quit. This will ensure that
the program is closed if the main window is closed using the 'X' at the
top right.
|
Congratulations! You have now not only created an interface which will
build the frontend for your first project, but you have also a created
a compilable, working program!
Note that the procedure so far for using Glade is the same if you have
chosen GTK4Win or Dev-C++ with DevEx. The remainder of the procedure
with GTK4Win is explained in the GTK4Win included documentaion, and if you
choose Dev-C++ you simply make use of the GTK+ tamplate, and add your C source
files to the project you have created! The next few paragraps of the
procedure is concerned with the use of winGTK so if you are using Dev-C++
you can skip down to the paragrap headed "Editing the code".
- Click at Project Options from the main Glade window.
Set your project directory as, say, C:\PROJECTS\FIRST. Have
a look around for other options there and finally click OK
. Leave the source type set to 'C' - the other options are not yet in
operation. Don't worry though, if you want to build a C++ project,
just re-mame the source files and include C++ coding!
- Click Save and then Build the Source from the
main Glade window. This creates the code of your project.
- Now open a DOS shell by: Start > Programs > MS-DOS
Prompt . Then type the following at the prompt (if you prefer,
you can use Notepad to do the editing).
cd C:\Projects\First
{Press Enter}
copy C:\winGTK\makefile {Press
Enter}
edit makefile {Press Enter}
- Now change the makefile according to your needs. For this
tutorial, change the executable file to "src\first.exe". Check
the entries in the Source files section below it. When you are satisfied
with it, save this file and exit (press Alt + F to invoke
the File menu).
- When you are back at the command prompt, type
make to compile your files. If they compile successfully,
type src\first to execute your
project.
- If your project runs successfully, you should see your program
running.
- Click the 'Click-me' button. Nothing happens. We
will do something about this in the next stage. Now click the 'Exit'
button. Your program should close.
- When you are through with it, go back to the already
open DOS window and type exit
to close it.
Editing your code
- Now use your file manager to take a look at what Glade
has created. In your project directory, you will have a file with
the extension '.glade'. This is your Glade project file ready
for further alteration. There will also be a sub-directory called
'src' in which you will find the four C source files that Glade has
made. Open the one named 'callbacks.c' using notepad or edit.
You will see that callbacks.c contains an empty function called 'on_button2_clicked'.
Your code goes into this function. Insert the line
#include <windows.h> amongst the include names at the top
of the code, and insert the following into the on_button2_clicked
function (between the curly braces { } ):
MessageBox (0, "Hello World\nfrom
My First Program!\n", "My First MessageBox", MB_ICONINFORMATION);
- Now re-build your program and test it. You have
a working program in which both buttons do an operation, and you have
seen the way in which the files produced by Glade allow you to insert
and use your own code. When you have finished, you are ready to
look at more complicated examples and methods in the further tutorials
First Example
and Second Example
.
All the examples in these exercises are available in one file (
Projects.zip
) which you can download.