如何使用 HTML/CSS UI 构建本地 C + + 应用程序?

是否有可能开发一个 C + + 程序,同时使用 HTML 和 CSS 作为用户界面?我知道如何使用 Webkit 容器使用 Javascript 进行编程,但是我对 C + + 开发非常感兴趣。

当我在 Windows 下开发的时候,我喜欢上了 C # WPF,但是现在我转移到了 Linux,我还没有找到一个好的工具来为界面使用标记。为此,我想将 HTML 和 CSS (它们非常轻量级且易于使用)与 C + + 代码以及类似 WPF 的东西混合在一起。

哦,还有一件事: 我在寻找桌面开发,而不是网页。

121863 次浏览

Yes, it is possible. What you want is a C++ web framework. You could start by looking at CppCMS—a Free High Performance Web Development Framework (not a CMS) aimed for Rapid Web Application Development.

Edit: After the question has been clarified, I think Awesomium would be a good fit for your needs.

You can achieve the same functionality by embedding WebKit (or Gecko) but as far as I know that is exactly what Awesomium does behind the scenes.

An alternative is librocket—a C++ interface middleware package designed for game applications. As you can guess from the description it is a good fit for games or real-time applications.

Sciter is exactly that - embeddable HTML/CSS engine with C/C++ API. Compact and multi-platform.

And check this article.

Sciter has the same feature set as WPF but uses HTML/CSS instead of XAML and uses native API.

Features out of the box:

  • HTML, CSS, SVG, aPNG (animated PNGs), image sprites,
  • <plaintext> - editor with syntax highlighting,
  • <htmlarea> - WYSIWYG HTML editor,
  • <frame type=pager> - print preview and HTML/CSS print,
  • animations,
  • HTTP client, REST/JSON client, WebSocket's, DataSockets,
  • etc.

The same application with Sciter UI running on Windows, MacOS and Linux from the same sources:

enter image description here

Disclaimer: I am an author of Sciter Engine.

2021 update: you can also use Sciter.JS that is version of Sciter that uses standard JavaScript (ES2020) script engine.

You can use Chromium Embedded Framework to embed HTML5 content in your app. You'll get might and speed of Chromium and ability to build GUI apps the same way you develop web applications.

I think Electron would be a nice addition to the other answers.

It uses NodeJS to run a Webkit Window. Electron itself is only html/css/js, but you can use any Node Module within your Electron App - including custom, natively compiled C++ code. A possible Module to embed your C++ code would be node-gyp.

Be aware, however, that this workflow may include a little bit more JS than you would have with the other answers.

My favourite text editor, Atom, was made with Electron.

I suggest checking out Ultralight HTML UI Engine
Not Open Source, Available for C++. OpenGL and DirectX rendering supported.

Ultralight is the lighter, faster option to integrate HTML UI in your C++ app.

It's made by the creator of Awesomium, who unfortunately decided to delete Awesomium.

If you need something more heavy weight I recommend taking a look at CEF. It’s a very powerful (and open source) tool.

I would suggest RmlUI

Its an active fork of librocket with more features. Its very modular, you can handle rendering, event handling and user input yourself (or copy one from provided examples).

Demo Game Menu Screenshot

Note: RmlUI doesn't support full HTML5/CSS3 specifications, but only a subset of it. Animations are supported tho.