I'm learning C (I just finished Chapter 2 or Unit 2) of the C Programming Language, I skimmed to the end and saw that at no point anything was said about how to create a GUI, and from what I've looked up, it seems I have to use a framework, but I hate the idea of that. How would I create a GUI without a framework? How exactly do these frameworks work and what language are they written in? I'm not making a massive application, even if it takes me a week, would it be feasible to write a GUI application (in C) to do something simple like creating a window?
4 Answers
You can build your own framework based on OpenGL or Xlib. Or use good graphics library like Motif or CGUI. Or use something awful like GTK.

- 864
- 6
- 14
-
why do you like cgui and motif and what is your gripe with gtk? isn't firefox made with gtk? – David Mar 06 '13 at 07:48
-
@David, GTK is awful library: not only by exterior but by its inner structure (a glib-based structures is a real nightmare, it's almost like Qt)! – Eddy_Em Mar 06 '13 at 07:49
Not the best road to take. I would suggest a cross platform library, like GTK+.

- 5,063
- 1
- 17
- 21
-
Okay so how do I use GtK? I know how to use winapi (c#.. .net framework, etc) but how do I use GTK? – – David Mar 06 '13 at 07:20
Yeah, no go.
C can't do anything except manage memory and possibly do software interrupts (if you do pointer hacking).
You need a library to do anything.
GUI is very complex, you can't do anything "simple" with it. It's a problem I face every single day.
If you want a window in C, you need X11, GTK, Windows API, Video hacking, or other fun stuff.
Oh, and Video hacking is a no go, OS will throw an exception if you even try to touch video memory without its permission.
Oh, and the "simple button" you speak of, in Windows API is actually a Window itself, not very simple.

- 5,068
- 4
- 39
- 50
-
"OS will throw an exception if you even try to touch video memory without its permission." - it's rather that userland processes have access to virtual memory, so treating addresses as physical addresses won't work. – Mar 06 '13 at 07:17
-
Okay so how do I use GtK? I know how to use winapi (c#.. .net framework, etc) but how do I use GTK? – David Mar 06 '13 at 07:19
-
The tutorials for setting up GTK on Debian based systems is very very simple. the compilation requires "gcc helloworld.c -o helloworld `pkg-config --cflags gtk+-2.0`" or something along those lines. with apt-get you can set up gtk in mere minutes. Although, good luck using it elsewhere. It took me several days to set up on Windows. And I haven't really used many unix based systems other than Ubuntu and Fedora (on which I have never used gtk). – Dmytro Mar 06 '13 at 07:20
-
I'm currently using fedora lxde spin for development and fedora gnome for desktop. – David Mar 06 '13 at 07:25
You can make a basic framework using the WINAPI
There is a great tutorial here.
The problem with using C and primitive frameworks like WINAPI is that manging layout and state becomes exceedingly difficult.
If you targeting a normal operating system, the C
only requirement becomes unreasonable. I recommend you go with C++
and Qt
and compile your C
code in a C++
compiler.

- 7,749
- 11
- 62
- 136
-
Sorry, but any WINAPI stuff is a no-go, this needs to be cross-platform, I'm a linux user. – David Mar 06 '13 at 07:17
-