开发者

What is the best way to design GUI Applications with C? [closed]

开发者_StackOverflow中文版 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

I always find good tutorials on the subject, but it almost always is C++. Is it hard or just doesn't make sense to make GUI applications with C?

A good book, guide or a tutorial is fine.

Platform: Linux


Use GTK+. It's written in C and exposes a well-designed C API. Their tutorial is quite excellent.

GTK+ is the toolkit for GNOME, so your applications will fit right in with many Linux desktops.


If you are programming in C on Windows - Petzold's programming windows used to be the bible for C based ui work.

EDIT: Since I answered my question the post has been updated to be on Linux. I will leave the post here for anybody looking, but it really does not apply to Linux.


Many high quality GUI were written in C with, for example, Windows API. There's no particular reason why not, but object oriented programming was very successful in modeling interactive graphics. GUI elements somehow map naturally into C++ objects that can encapsulate complex behavior behind a simple interface.


It's hard enough (or, mostly, verbose enough) that most people figure it just doesn't make sense. The GUI part of an application (mostly) reacts to user input, so in this area speed is rarely critical -- a difference of a few microseconds (or even milliseconds) rarely makes much difference. As long as responses appear within 100 ms (or so), they're pretty much perceived as "instant".

Dynamic typing also tends to work quite nicely for a lot of GUI programming. C uses only static typing.


Don't.

Use python and then bind the computationally expensive calls written in C.


What is the best way to design GUI Applications with C?

don't, if you don't have to :-)

Is it hard or just doesn't make sense to make GUI applications with C?

It is not necessarily that hard, but a pretty redundant and verbose task (like writing high level programs in assembly language), with lots of repeated boilerplate code.

Personally, I find it more rewarding to simply embed a scripting interpreter (e.g. Lua, Nasal) with bindings for a GUI library and then code the UI in a high level scripting language and code only the core of the application itself in C. Python was previously mentioned, but I think that a dedicated extension language like Lua would be a better fit, because it doesn't bloat your source code and because it does not create any additional requirements (like library dependencies or architectural).

In other words, embedding something like Python, Perl or Ruby may be relatively straight forward (because of good documentation and community momentum), but often these languages are more complex than the host application itself.

This is also the approach taken by the AlgoScore software, which uses an embedded Nasal interpreter with GTK bindings.


If you're on a *nix system, you can use Xlib. But you're probably better off programming in C++ and calling out to your C code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜