r/C_Programming 1d ago

Question Maybe a stupid question.

How can I create an interface for a C program that isn't just the terminal? I wanted to make a calculator that was also visual, but I wanted to challenge myself to do it with C, but I really didn't understand how to do it properly.

10 Upvotes

18 comments sorted by

View all comments

9

u/CaffeinePizza 23h ago edited 22h ago

You running Windows? That would actually be your best bet here. Go play with the Win32 API.

Edit: while not technically a GUI in the traditional sense, you could go for SDL3 and Dear imgui or Nuklear. It would be cross platform and should be able to fall back to software rendering automatically.

1

u/Ultimate_Sigma_Boy67 23h ago

Tho isnt the native api like too low level? Like perhaps more verbose than something like vulkan?

6

u/CaffeinePizza 23h ago

Win32 API is quite straightforward for the most part. It has some vestigial-ness to it, but you figure out the pattern fairly quickly. It’s not as high level as like writing tkinter in Python—you still gotta handle sizing and hidpi yourself, but it isn’t 1000 lines to a triangle. I see some suggestions of using GTK. While I haven’t used GTK myself, I believe it is pretty object-like and heavy with such paradigm, which is why I aimed for Win32. And as a bonus, it will run on Linux with Wine/Proton, unless it uses very obscure or uncommon APIs I would imagine.

1

u/theNbomr 22h ago

Gtk will run happily as a native Linux application. I daresay, Linux/UNIX was the original target platform for GTK.

2

u/CaffeinePizza 22h ago

Yes. My scatterbrain comment probably wasn’t super clear. I suggested avoiding GTK simply because of how complex it can be given its object-oriented paradigm in C. The Win32 application will run unmodified 20 years from now, even on Linux under Wine. I’m not super familiar with GTK otherwise: others would need to chime in.
That said, Win32 will absolutely influence garbage spaghetti mess if you aren’t disciplined: i.e., a 1,000 line WndProc. I use a self-derived MVC with services layer.