Making a GUI without a framework in C

2019-03-27 04:55发布

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条回答
叼着烟拽天下
2楼-- · 2019-03-27 05:21

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.

查看更多
家丑人穷心不美
3楼-- · 2019-03-27 05:21

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.

查看更多
够拽才男人
4楼-- · 2019-03-27 05:39

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楼-- · 2019-03-27 05:43

Not the best road to take. I would suggest a cross platform library, like GTK+.

查看更多
登录 后发表回答