如果你用过QT和MFC,那你必然知道QT是基于C++的跨平台库,而MFC是微软针对widows平台推出来基础类库。且不论MFC的设计如何,从我个人和身边朋友的经历来看,MFC是一些非常难以理解的类的组合,其设计模式和各式各样不知所谓的宏都让人十分费解。相比之下,QT在这方面要好很多。哈哈,你以为我会介绍QT吧?错了,QT大家都都很熟悉了。在这里给大家推荐的是 juce,一个跨平台的C++用户界面库。

Juce的主页是:http://www.juce.com

据说当初主要是在音频处理领域用得比较多,因此包含了比较多的音频相关代码。后来推广到各个领域,如图形图像,GUI等。

个人感觉,Juce的设计思想与android的基础类库思想比较接近。因此,如果你会android编程,那juce用起来就会似曾相识,比如两者都采用多继承等。相比之一,juce的代码看起来更为简洁。同时juce创建的用户界面也比较简洁美观。下面给出一个例子说明。

程序启动后的样子:

外观样式默认是mac风格的。在这里添加几行代码,实现一个简单的交互,在按下按钮后提示按钮已按下:

整个程序的代码如下:

Maincomponet.h:

/*==============================================================================This file was auto-generated!==============================================================================
*/#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED#include "../JuceLibraryCode/JuceHeader.h"//==============================================================================
/*This component lives inside our window, and this is where you should put allyour controls and content.
*/
class MainContentComponent   : public Component,public ButtonListener
{
public://==============================================================================MainContentComponent();~MainContentComponent();void paint (Graphics&);void resized();void buttonClicked(Button* button);
private:TextButton* button1;String msg;
private://==============================================================================JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};#endif  // MAINCOMPONENT_H_INCLUDED

MainComponent.cpp:

/*==============================================================================This file was auto-generated!==============================================================================
*/#include "MainComponent.h"//==============================================================================
MainContentComponent::MainContentComponent()
{setSize (500, 400);button1 = new TextButton("click me");;addAndMakeVisible(button1);button1->setBounds (10, 10, 75, 30);button1->addListener(this);msg = "Hello World!";}MainContentComponent::~MainContentComponent()
{deleteAllChildren();
}
void MainContentComponent::buttonClicked(Button* button)
{if(button == button1){msg = "button clicked!";this->repaint();}
}
void MainContentComponent::paint (Graphics& g)
{g.fillAll (Colour (0xffeeddff));g.setFont (Font (16.0f));g.setColour (Colours::black);g.drawText (msg, getLocalBounds(), Justification::centred, true);
}void MainContentComponent::resized()
{// This is called when the MainContentComponent is resized.// If you add any child components, this is where you should// update their positions.
}

main.cpp:

/*==============================================================================This file was auto-generated by the Introjucer!It contains the basic startup code for a Juce application.==============================================================================
*/#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"//==============================================================================
class myguiApplication  : public JUCEApplication
{
public://==============================================================================myguiApplication() {}const String getApplicationName()       { return ProjectInfo::projectName; }const String getApplicationVersion()    { return ProjectInfo::versionString; }bool moreThanOneInstanceAllowed()       { return true; }//==============================================================================void initialise (const String& commandLine){// This method is where you should put your application's initialisation code..mainWindow = new MainWindow();}void shutdown(){// Add your application's shutdown code here..mainWindow = nullptr; // (deletes our window)}//==============================================================================void systemRequestedQuit(){// This is called when the app is being asked to quit: you can ignore this// request and let the app carry on running, or call quit() to allow the app to close.quit();}void anotherInstanceStarted (const String& commandLine){// When another instance of the app is launched while this one is running,// this method is invoked, and the commandLine parameter tells you what// the other instance's command-line arguments were.}//==============================================================================/*This class implements the desktop window that contains an instance ofour MainContentComponent class.*/class MainWindow    : public DocumentWindow{public:MainWindow()  : DocumentWindow ("MainWindow",Colours::lightgrey,DocumentWindow::allButtons){setContentOwned (new MainContentComponent(), true);centreWithSize (getWidth(), getHeight());setVisible (true);}void closeButtonPressed(){// This is called when the user tries to close this window. Here, we'll just// ask the app to quit when this happens, but you can change this to do// whatever you need.JUCEApplication::getInstance()->systemRequestedQuit();}/* Note: Be careful if you override any DocumentWindow methods - the baseclass uses a lot of them, so by overriding you might break its functionality.It's best to do all your work in your content component instead, but ifyou really have to override any DocumentWindow methods, make sure yoursubclass also calls the superclass's method.*/private:JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)};private:ScopedPointer<MainWindow> mainWindow;
};//==============================================================================
// This macro generates the main() routine that launches the app.
START_JUCE_APPLICATION (myguiApplication)

整个演示程序只需以上的代码,比起MFC来够简洁了吧! 另外,你也许注意到了,以上的代码大部分是自动生成的。的确,juce提供了一个自动创建项目的小程序,叫做introjucer,在你下载的juce包里,用vs编译一下即可用。

对了,juce的下载地址是:https://github.com/julianstorer/JUCE,文档地址:http://www.juce.com/documentation

上面的文档事实上不太利于理解juce,建议看这个:

http://lubyk.org/en/software/mimas/document171.pdf

或者从这里下载。

juce: 跨平台的C++用户界面库相关推荐

  1. material-ui_满足Material-UI —您最喜欢的新用户界面库

    material-ui by Code Realm 通过Code Realm 满足Material-UI -您最喜欢的新用户界面库 (Meet Material-UI - your new favor ...

  2. OpenGL Ant Tweak Bar的用户界面库

    OpenGL Ant Tweak Bar的用户界面库 OpenGL的Ant Tweak Bar库 安装 一体化 初始化 事件处理 创建一个界面 渲染界面 添加小部件 源代码实例 OpenGL的Ant ...

  3. 【GUI制作】tkinter-一款跨平台的简易GUI库

    前言 Tkinter 模块(Tk 接口)是 Python 的标准 Tk GUI 工具包的接口,是Python内的一个基础GUI库,广泛应用于需要简单GUI的应用场景,编程时不支持界面与逻辑分离,因此有 ...

  4. C/C++ 跨平台交叉编译、静态库/动态库编译、MinGW、Cygwin、CodeBlocks使用原理及链接参数选项

    0. 引言 UNIX是一个注册商标,是要满足一大堆条件并且支付可观费用才能够被授权使用的一个操作系统.linux是unix的克隆版本,是由其创始人Linus和诸多世界知名的黑客手工打造的一个操作系统. ...

  5. VS2019 C++跨平台开发 Android So 库

    一.VS2019 软件配置 1.1 下载VS2019 Android 开发工具 在获取工具和功能中,勾选下载 Android 开发工具(包含SDK)和 NDK. 1.2 配置 Android SDK ...

  6. 谈跨平台C++动态连接库的实现

    我对与solaris ,hp ,windows这三个平台的动态库的实现,进行了探索,对于soloaris,hp等Unix平台来讲,主要是make文件的制作,而Windows下还需要对类头进行修饰. 本 ...

  7. python图形化编程wx_慢步python,图形用户界面库:wxPython库 初体验,先建一个窗体...

    慢步写文的初衷是,帮助python爱好者学习python编程.(因为慢步也知道学习不易) 今天慢步要建立一个程序的窗体.什么是窗体?慢步水平及时间有限,直接上图吧. 就是图中的"简单界面&q ...

  8. .NET跨平台开源控件库-SukiUI

    目录 ✨ SukiUI UI主题, AvaloniaUI的一款桌面端和移动端控件库 !

  9. dataguard跨平台linux,Dataguard从库性能的监控

    [前言]Oracle 11G开始支持了active dataguard,这时候从库就可以分担一些主库的读的压力了.这种架构有个问题就是从库的性能压力很难排除出来.有个朋友也是使用从库进行数据的抽取,但 ...

最新文章

  1. linux 常用的系统信息查看命令
  2. 递归 累加和累乘
  3. 超百家金融机构争相出席,只因飞贷宣布输出全球领先的移动信贷整体技术
  4. CentOS 7环境安装Docker
  5. lisp 河道水面线计算_天然河道水面线计算的几种方法解剖.pdf
  6. 免费开源剪辑软件Shotcut推荐和使用教程
  7. python invalid literal for int_求助!运行出现错误“ValueError: invalid literal for int() ··...
  8. SQLSERVER查询存储过程内容
  9. (40)VHDL实现移位寄存器(方法2)
  10. python静态递归函数_python—递归函数
  11. python c++ socket 通信一个示例
  12. 2017大学网考计算机b,(热)2017年4月网考 大学英语b网考 电大英语网考 计算机应用.doc...
  13. ubuntu 键盘输入法为空_[已解决]HELP!!!fcitx 输入法不出来,键盘也不见了
  14. 家庭NAS方案-树莓派安装使用OpenMediaVault
  15. 蓝桥杯基础练习python
  16. 发起AI联盟,天猫精灵CES布局智能家居市场
  17. 方差与偏差的意义与推导过程
  18. Some useful linux commands
  19. 设计一个三阶巴特沃斯滤波器_设计巴特沃斯滤波器只需要确定两个参数,是什么?...
  20. JS常用代码片段-127个常用罗列-值得收藏

热门文章

  1. C2P工业云ERP企业管理软件的作用
  2. android studo 3.0 搜狗输入法问题 终结者
  3. Couldn‘t find Lora with name guofeng3_v32Light 0% 0/20 [00:00<?, ?it/s] Error completing request A
  4. 新建一个Menu菜单项
  5. ubuntu桌面特效
  6. 一个开源的网Y云音乐api项目,足够你玩了。
  7. abb机器人指令手册_爆!!ABB机器人支持OPC UA了
  8. 腾讯云服务器配置https 部署安装ssl证书
  9. Java视频教程,java全套教程从入门到精通:13天学会Java编程!
  10. Pandas——ix vs loc vs iloc区别