tags:

views:

750

answers:

10

Hello there,

I'm new GUI and programming as whole and so far I have a general understanding of c and have spent quite some time writing console applications.

I'm trying to learn GUI but have so far been unsuccessful. I've tried learning wxwidgets (through official documentation), gtk (through official documentation) and win32 (forgers win32 tutorial) but still haven't quite gotten there.

I still really want to but can't seem to find any good material. What would you recommend as start for a beginner?

A: 

I recommend Cimg library that is open source and very use full in 2'D graphical interface and image processing :

The CImg Library is an open source C++ toolkit for image processing designed with these properties in mind : Usefulness CImg defines simple classes and methods aimed at manipulating generic images in your own C++ code : Load/save various file formats, access pixel values, display, resize/rotate/mirror/filter, draw primitives (text, faces, curves, 3D objects, ...), compute statistics, manage user interactions, and so on... Genericity Provided image classes can represent datasets up to 4-dimension wide (from 1D scalar signals to 3D hyperspectral volumes), with template pixel types. Image collections and sequences are also supported. Portability CImg is self-contained and thus highly portable. It fully works on different operating systems (Unix, Windows, MacOS X, *BSD) with various C++ compilers (Visual C++, GNU g++, Intel icc, Borland bcc, ...). Simplicity CImg is lightweight. It is made of a single header file CImg.h that must be included in your C++ source. It defines only four different classes. It can be compiled using a minimal set of standard C++ and system libraries. No need for exotic or complex dependencies. Extensibility Although not required, CImg can use functionalities of external tools/libraries such as ImageMagick, GraphicsMagick, XMedCon, FFMPEG, libpng, libjpeg, libtiff, Magick++, Lapack, Board, OpenEXR or FFTW3. Moreover, a simple plug-in mechanism allows any user to directly enhance the library capabilities according to his needs. Freedom CImg is a free, open-source library distributed under the CeCILL-C (close to the GNU LGPL) or CeCILL (compatible with the GNU GPL) licenses. It can be used in commercial applications.

This is document for Cimg.

SjB
Voted down because wall of text. And open source is sometimes not the best way to start learning reading the code. Can give you a warped perspective of what real written software should look like.
Chad
@Chad Cimg is simplest graphic library that i see . Do you see Cimg library yet ?
SjB
@chad, and how else do you suggest to learn what real written software should look like? At least with open source, reading the code is an option. Reading any code is better than just venturing off into the void and having to figure it all out from scratch or just using trivial examples from books and tutorials.
mcl
The biggest problem I see is that is C++ and not C as the OP asked...
Remo.D
@mclIn the C++ language area I would recommend John Carmack Quake 3 engine written in mostly C. Next I would recommend Half life 2 SDK. Adobe open source products (Though I'm reluctant to recommending it). The reason why I recommend ANY commercial software product over open source is the cultural difference, and cultural values. The reason for sighting commercial products is because they're successful and that code base has run on millions of machines! That's something in itself.
Chad
@mcl There is nothing wrong with venturing off into the void and figuring it all from scratch. It's great fun, and you will learn very quick lesson's that would otherwise taken months to gain from reading books. Though I recommend stackoverflow + venturing out, because you get a large amount of knowledge at your finger tips.Though, don't take my comment the wrong way. I'm mostly advicating commerical software products over open source for only cultural value reasons. Then using stackoverflow with tutorials and branching out on your own to make learning more engaging.
Chad
+2  A: 

I'd suggest you should try to learn some object oriented programming properly with a language such as Objective C or C++, since GUI programming is difficult. Particularly even more so in C.

A lot of the concepts in GUI programming revolves about you knowing how objects work, with all the widgets that are composed in any GUI framework, and how they interact together. There is also the concept of events that sends messages from one input source to a graphical component (or between two graphical components).

In summary: it becomes a lot easier to read through documentation when you know what the objects are all about… and even then there is a lot to take in.

Spoike
+1  A: 

Reading a book will only get you so far. To take it to the next level you just need to experiment with what the API can do. Though you could get all down to the Win32 API level for your GUI, but if your just starting out just focus on trying different techniques out.

You will soon find out what works and what doesn't work.

If I would recommend a book I would recommend a nontechnical book.

Design Of Everyday Things

Next is a video post cast, about more psychological overview of designing a GUI and how to make your users and you happy.

Business of software - Joel Spolsky

Last one, this book will help you understand that, when you do design applications that people will view your asthetic decisions and choices via their own culture values. So, its important to choose one asthetic design theme for your application and stick with it.

The Culture Code

Chad
+1  A: 

The thing to know is that GUI isn't built into C (as you've no doubt already found out) but is bolted on via various libraries. wxWindows, qt, gtk and of course the VCL are major players. While they all do similar things, they're all different in detail.

Something important to know is that if you were to program in C++, you'd have access to some object-oriented wrappers to these and other libraries that might make your life a little easier. "plain" C is sometimes looked down on as "old school" these days, and support is not quite as "lively" - though the existing GUI libraries are excellent in their own right.

What I recommend is that you browse through the 'net for descriptions and comparisons of GUI libraries and evaluate your findings against your personal needs. Will your stuff run only on Windows, or would you like it cross-platform? Is licensing an issue? Do you want small and simple (and perhaps not so sexy) or do you want the GUI to end all GUIs?

Having picked a winner, work through online tutorials or examples. If you manage to get the gist of it and can stand to program in the required style, grab a dead-tree book to learn it in depth and understand it in detail.

Carl Smotricz
+8  A: 

If you are strictly limited to C, you have only a few choices. GTK+ is probably the easiest for a beginner.

An object oriented language like C++ is far more suited to GUI programming. If you like to use C++, I strongly recommend Qt, mainly because of its very good documentation, with very good tutorials especially for beginners.

drhirsch
-1, given that the question mentions having tried gtk, recommending gtk is redundant without offering tips for how to crack that nut. Also recommending to switch languages is beside the point. OO languages are not more suited to GUI programming because OO is just a design practice, not some magic that's only available in certain languages.
mcl
Really. So you do think C is equally well suited for GUI programming? Go ahead and do program your GUIs in C, I won't hold you back. So what is your recommendation for a beginner who wants to do some GUI programming?
drhirsch
Gtk+. As you can see from my answer. I don't know why sil3nt chose C (apparently on Windows), but s/he must have reasons. I think the insistence on one language over another is distracting. If language choice is truly an open question at this point, I'd suggest C# as the best way for a Windows programmer to get into GUI programming.
mcl
VisualBasic wasn't any more object oriented than C yet anyone could use to write GUI applications. If toolkits weren't written to make interfacing with them in C virtually impossible(Qt/Cocoa) or just not intended for modern GUI programming(WinAPI) it could be a piece of cake. The advice to move to C++ and Objective C for the GUI code at least is probably valid, though.
jbcreix
+1  A: 

If you want to learn GUI programming on Windows in C, the good news is that the native API is all based on C. The bad news is that the native API is not exactly a model of clearness and consistency. It is much easier to start with an OO framework built on top of that API.

That being said, if you still want to learn Windows GUI programming in C, your best bet is Petzold's Programming Windows. It will teach you Windows programming in general, including all the GUI stuff, using the native API.

Ferruccio
+3  A: 

I wouldn't suggest trying to do GUI with C. It's not really that comfortable to do so.

But if you really want to do it. Here's a quite nice tutorial on Windows API.

You can also use a library like Allegro, it is meant for games, but can be equally useful in programs.

But the way I would suggest is, first learn the basics of GUI and application (that means state machine) programming with a simple language (any simple will do, personally would suggest Lua with Löve2D platform). And then use the knowledge you got in C. The state machine and event-flow will be harder to grasp if you have to deal with garbage collection and pointers... (it's still possible to learn).

egon
-1 because the question wasn't whether GUI should be done in C, but how to get started. There is an abundance of fine software written in C using Gtk+ that runs cross-platform.
mcl
+1 The question includes "What would you recommend as start for a beginner?" Therefore it is perfectly good advice to throw in a caveat in addition to giving a valid answer to the rest of the question.
Dipstick
@mcl: I know that there is a lot of software written GUI in C. There's also GUI applications written in asm. But I wouldn't think that would be the best way to trying to learn GUI. I think for beginners learning GUI first with something like Lua (like Löve2D platform) would be more benefitial as you wouldn't have to worry about gc, pointers and other similar stuff. When you know the basic event/state model for GUIs then moving on is easier.
egon
Speaking from experience, I'd say finding a simple app written in your chosen programming language and chosen GUI toolkit is an excellent way to learn GUI programming. I did this with a Mandelbrot set plotter written in C using GTK. I ported it to GTK2 and implemented new features (and thus new dialog boxes etc). The key here is to find a simple app which you're reasonably confident you can get to grips with to add or modify.
James Morris
+2  A: 

I am going to recommend going back to gtk+ and trying it more. Why?

Because there is a wealth of open source software available for both Linux and Windows written in C using the gtk+ libraries for the GUI. From large applications like the GIMP and GnuCash, to smaller tools, the source code is available that you can read to find out how they accomplish certain feats. Whether they set the best example for how to accomplish something is another question, but at least you have the advantage to see how working software does its thing.

Also, gtk+ includes glib, which is a handy tool to have available for handling common data structures and algorithms. So instead of spending your time implementing linked lists and stuff, you can just use the ones in the library and your coding time is spent solving your own particular puzzles.

Gtk+ documentation is hardly perfect, but it's decent. There is a mailing list for app developers as well.

mcl
along with GTK+, Glade3 interface designer tool can be used. You can build your GUI form by just dragging and dropping the widgets. Glade generates .glade file which can be imported in your C code. For more information go to http://glade.gnome.org/
atv
A: 

+1 for GTK. If you're bound to using C, either through your own choice or project requirements, you'd have a hard time doing better than GTK+. QT is mostly C++, so if C++ is ok that's an option. But the docs for GTK+ are not too bad as open source projects go, and there's a lot of example code out there to look at.

If you have a choice of switching languages there are other options Cocoa is an excellent GUI programming environment on the Mac (I've never tried Cocoa for windows, but have heard that it's possible.) and Objective-C lends itself well to GUI programming.

alesplin
A: 

I suggest you also study up on Event Driven Programming. In many GUI programs, the main program waits for an event, such as a mouse click, to happen then processes the event. Event Driving Programming is a lot different than Sequential Execution programming.

Other topics to study are Multi-thread and Multi-task programming. Many GUI objects (widgets) such as a button, pass messages to other objects; or broadcast to all listeners. Message passing is a common process in Multi-thread and Multi-task programming.

Thomas Matthews