使用C设计GUI应用程序的最佳方法是什么?

时间:2022-05-26 05:07:25

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?

我总是找到关于这个主题的好教程,但它几乎总是C ++。使用C制作GUI应用程序是困难还是没有意义?

A good book, guide or a tutorial is fine.

一本好书,指南或教程都可以。

Platform: Linux

8 个解决方案

#1


7  

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

使用GTK +。它是用C语言编写的,并且公开了一个设计良好的C API。他们的教程非常好。

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

GTK +是GNOME的工具包,因此您的应用程序将适用于许多Linux桌面。

#2


6  

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

如果你在Windows上用C语言编程 - Petzold的编程窗口曾经是基于C语言的ui工作的圣经。

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.

编辑:由于我回答了我的问题,该帖子已更新为Linux。我会留下这里的帖子给任何人看,但它确实不适用于Linux。

#3


2  

Don't.

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

使用python然后绑定用C编写的计算成本高昂的调用。

#4


2  

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

使用C设计GUI应用程序的最佳方法是什么?

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

不,如果你不需要:-)

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

使用C制作GUI应用程序是困难还是没有意义?

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).

就个人而言,我发现简单地嵌入一个脚本解释器(例如Lua,Nasal)和GUI库的绑定然后用高级脚本语言编写UI并且只用C语言编写应用程序本身的核心就更有价值.Python是前面提到过,但我认为像Lua这样的专用扩展语言会更合适,因为它不会使你的源代码膨胀,也不会产生任何额外的需求(比如库依赖或架构)。

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.

换句话说,嵌入像Python,Perl或Ruby这样的东西可能相对简单(因为良好的文档和社区动力),但这些语言通常比宿主应用程序本身更复杂。

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

这也是AlgoScore软件采用的方法,它使用带有GTK绑定的嵌入式鼻腔解释器。

#5


2  

  • nCurses library of old-school DOS-style GUIs in C.

    n在C中存储旧式DOS风格的GUI库。

  • GTK would be fine for a modern GUI.

    GTK适用于现代GUI。

  • Use Qt for a cross-platform tool to develop GUIs over win/Linux/mac/embedded/symbian

    使用Qt作为跨平台工具,通过win / Linux / mac / embedded / symbian开发GUI

    http://qt.nokia.com/

#6


1  

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.

许多高质量的GUI都是用C语言编写的,例如Windows API。没有特别的原因,但面向对象编程在交互式图形建模方面非常成功。 GUI元素以某种方式自然地映射到C ++对象,这些对象可以在简单的接口后面封装复杂的行为。

#7


0  

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".

足够困难(或者,大多数情况下,足够详细),大多数人认为它没有意义。应用程序的GUI部分(主要是)对用户输入作出反应,因此在这个区域中,速度很少是关键的 - 几微秒(甚至几毫秒)的差异很少会产生很大的差异。只要响应在100毫秒(或左右)内出现,它们就会被视为“即时”。

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

对于许多GUI编程,动态类型也可以很好地工作。 C仅使用静态类型。

#8


-1  

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.

如果您使用的是* nix系统,则可以使用Xlib。但是你最好不要用C ++编程并调用你的C代码。

#1


7  

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

使用GTK +。它是用C语言编写的,并且公开了一个设计良好的C API。他们的教程非常好。

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

GTK +是GNOME的工具包,因此您的应用程序将适用于许多Linux桌面。

#2


6  

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

如果你在Windows上用C语言编程 - Petzold的编程窗口曾经是基于C语言的ui工作的圣经。

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.

编辑:由于我回答了我的问题,该帖子已更新为Linux。我会留下这里的帖子给任何人看,但它确实不适用于Linux。

#3


2  

Don't.

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

使用python然后绑定用C编写的计算成本高昂的调用。

#4


2  

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

使用C设计GUI应用程序的最佳方法是什么?

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

不,如果你不需要:-)

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

使用C制作GUI应用程序是困难还是没有意义?

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).

就个人而言,我发现简单地嵌入一个脚本解释器(例如Lua,Nasal)和GUI库的绑定然后用高级脚本语言编写UI并且只用C语言编写应用程序本身的核心就更有价值.Python是前面提到过,但我认为像Lua这样的专用扩展语言会更合适,因为它不会使你的源代码膨胀,也不会产生任何额外的需求(比如库依赖或架构)。

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.

换句话说,嵌入像Python,Perl或Ruby这样的东西可能相对简单(因为良好的文档和社区动力),但这些语言通常比宿主应用程序本身更复杂。

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

这也是AlgoScore软件采用的方法,它使用带有GTK绑定的嵌入式鼻腔解释器。

#5


2  

  • nCurses library of old-school DOS-style GUIs in C.

    n在C中存储旧式DOS风格的GUI库。

  • GTK would be fine for a modern GUI.

    GTK适用于现代GUI。

  • Use Qt for a cross-platform tool to develop GUIs over win/Linux/mac/embedded/symbian

    使用Qt作为跨平台工具,通过win / Linux / mac / embedded / symbian开发GUI

    http://qt.nokia.com/

#6


1  

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.

许多高质量的GUI都是用C语言编写的,例如Windows API。没有特别的原因,但面向对象编程在交互式图形建模方面非常成功。 GUI元素以某种方式自然地映射到C ++对象,这些对象可以在简单的接口后面封装复杂的行为。

#7


0  

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".

足够困难(或者,大多数情况下,足够详细),大多数人认为它没有意义。应用程序的GUI部分(主要是)对用户输入作出反应,因此在这个区域中,速度很少是关键的 - 几微秒(甚至几毫秒)的差异很少会产生很大的差异。只要响应在100毫秒(或左右)内出现,它们就会被视为“即时”。

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

对于许多GUI编程,动态类型也可以很好地工作。 C仅使用静态类型。

#8


-1  

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.

如果您使用的是* nix系统,则可以使用Xlib。但是你最好不要用C ++编程并调用你的C代码。