3

I'm learning C and want to write programs with GUI. Personally I'm OK with terminal in Linux or the black window in Windows. However, I want to write something that could be used by other non-professional users. So I wrote this post to ask how to write a GUI program in C (C++ is OK). What kind of books should I read? Or anything else I need to know. Thank you.

OneZero
  • 11,556
  • 15
  • 55
  • 92
  • Which one? They use completely different UI systems. – SLaks Apr 29 '12 at 21:50
  • 1
    http://stackoverflow.com/questions/2018850/cross-platform-c-library-for-gui-apps – Guillaume Paris Apr 29 '12 at 21:51
  • If you are more into C than C++ and use linux, go with GTK. The primary GUI frameworks on linux are GTK and (to a lesser extent) Qt, which is used by KDE. If you do go for GTK, learn version 3. There is also a C++ API for GTK (gtkmm). – CodeClown42 Apr 29 '12 at 22:02

4 Answers4

6

For pure C, you could use GTK+, but if you're familiar with C++ too, i 'd recommend Qt Framework from Nokia. There are over 100 of youtube videos for mastering Qt. Follow this link: Qt training

chemeng
  • 456
  • 1
  • 5
  • 18
3

For cross-platform (linux/windows/mac) in C, I think GTK is predominant but note that GTK is unlikely to be installed on most non-linux systems.

For cross-platform in C++, WxWidgets is popular because it uses the underlying native GUI library, hence the applications have a look and feel that blends in. There's also Qt, but this does not use the native infrastructure, so the applications do not blend in (unless the system is predominantly Qt, just as GTK does not blend in, unless the system is predominantly GTK).

Windows and linux have a native C GUI API (for linux, GTK, which as mentioned is also portable). I would guess that OSX uses objective C natively.

CodeClown42
  • 11,194
  • 1
  • 32
  • 67
  • 1
    OS X applications have a tendency to be written in Objective-C using the frameworks that come with OS X such as Cocoa. You _can_ write GUI applications in C or even use C++ with Qt to write applications. – lukecampbell Apr 29 '12 at 21:57
  • wx windows is bukake, technically –  Apr 29 '12 at 21:57
2

Depending on the OS, you'll have to look at some form of API that will communicate with said OS in order to program a GUI application.

On Windows it'd be good to become familiar with the Win32 API. Microsoft has a basic tutorial I'm personally not a fan of their documentation but it's a place to start.

For OSX, you have Cocoa, (although for that you'd have to learn Objective-C, which is based off C).

As for linux, it would appear that there are various toolkits you can use to program a GUI, such the previously mentioned GTK. (Which is cross-platform.)

n00begon
  • 3,503
  • 3
  • 29
  • 42
0

Since you clarified C under Linux, you would do well to learn GTK+.
If you want to use a text based user interface you can use the curses library.

Here is a book you might pick up to learn GTK+

Chimera
  • 5,884
  • 7
  • 49
  • 81