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
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.
-
"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.– user529758Mar 6, 2013 at 7:17
-
Okay so how do I use GtK? I know how to use winapi (c#.. .net framework, etc) but how do I use GTK?– DavidMar 6, 2013 at 7: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).– DmytroMar 6, 2013 at 7:20 -
I'm currently using fedora lxde spin for development and fedora gnome for desktop.– DavidMar 6, 2013 at 7: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.
-
Sorry, but any WINAPI stuff is a no-go, this needs to be cross-platform, I'm a linux user.– DavidMar 6, 2013 at 7:17
-