Thread: Generate graphics?

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    48

    Generate graphics?

    Hello

    I've finished reading my school's C book which covered arrays, functions, pointers and files and I've started reading the C++ book for next semester and its mostly about OOP, which made me wonder, how to do create programs that actually have a GUI? Lets say you want to create a calculator with a GUI that runs under Linux and UNIX. How would you do that? Are most GUI programs made with C or C++ if not what?

    Thanks

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    KDE, and most KDE programs, are written in C++.
    Gnome, and many Gnome programs, are written in C.

    You can write graphical programs with just about any language, however.

    To create a GUI, you have to use a library of some sort. The C++ Qt (which is what KDE uses), the C GTK+ (which is what Gnome uses), and the C++ wxWidgets are a few common ones.

    [edit] The only graphical calculator I have created on this computer is written in Perl.

    One thing you should keep in mind is that creating GUI programs is complicated. Have a look at the length of this Hello, World! program in GTK+, for example.
    http://library.gnome.org/devel/gtk-t...SEC-HELLOWORLD [/edit]
    Last edited by dwks; 06-13-2008 at 04:59 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    For GUIs, OOP is very useful. But like dwks said, you can do it in C with libraries like GTK+ which implement many OOP features. I had a go at GTK+ and I quite liked it; I'd recommend giving it a try.

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    48
    Thanks, now I can start learning it

    Can you also tell me what I need to create GUI for windows?

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    There is a Windows port of Gtk+

    Otherwise you'd have to use the Win32 API (see msdn.microsoft.com).

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by zacs7 View Post
    There is a Windows port of Gtk+

    Otherwise you'd have to use the Win32 API (see msdn.microsoft.com).
    You don't HAVE to program straight Win32, in fact, hardly anybody does that any more. There are graphical GUI design tools available for native Windows (i.e. no "toolkit"), and some of them work quite well.

    I'm a big fan of total decoupling of interface from function -- the GUI is nothing but a shell which calls out to the app. This way you can completely redesign the GUI, even switching to another language if you want to, without affecting the program logic.

  7. #7
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    I'm a big fan of total decoupling of interface from function -- the GUI is nothing but a shell which calls out to the app. This way you can completely redesign the GUI, even switching to another language if you want to, without affecting the program logic.
    How do you do that? Pipes, a library or something else?

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by zacs7 View Post
    How do you do that? Pipes, a library or something else?
    However you want

    Depends how much you really want to decouple. Keeping the GUI in its own DLL is better than nothing, but it shares VM with the application, so bugs in the GUI can crash the whole app. A pipe is a good solution. Any IPC method the OS gives you could potentially be used.

    Pipes, sockets, DDE, message exchange... Lots of options.

    Admittedly, this is not popular on Windows. I try to go against the flow.

  9. #9
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I'm a big fan of total decoupling of interface from function -- the GUI is nothing but a shell which calls out to the app. This way you can completely redesign the GUI, even switching to another language if you want to, without affecting the program logic.
    I'm not sure if I agree with that. When I started out doing GUIs I tried separating the front and backends as much as possible.

    Generally speaking the backend dealt with the functionality and held all the data. The front end would be full of widgets which in most cases simply duplicated the backend data. Whenever something is done in the frontend it gets sent to the backend which does blahdeblah and send it to the frontend.

    Personally I found this made everything more complicated, took longer to code, was more prone to bugs, and used more resources. While I can understand decoupling something thats likely to do a lot (like a graphics buffer with all the drawing stuff), most things a GUI does tend to be pretty simple. So far I havent seen any real benefits to decoupling everything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  2. Template metaprogramming, whats the point?
    By Cogman in forum C++ Programming
    Replies: 26
    Last Post: 02-01-2009, 11:47 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 08:33 PM
  4. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  5. Graphics Devices and Cprintf clash
    By etnies in forum C Programming
    Replies: 6
    Last Post: 05-09-2002, 11:14 AM