如果你用过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 all
your 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 of
our 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 base
class 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 if
you really have to override any DocumentWindow methods, make sure your
subclass 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. 玩node-images模块---Node.js轻量级跨平台图像编解码库

    Node.js轻量级跨平台图像编解码库 github:https://github.com/zhangyuanwei/node-images Features 功能特性 轻量级:无需安装任何图像处理库 ...

  2. Windows平台下和跨平台的相关公共库

    以下主要包含windows下公共库以及跨平台公共库: 1. google base库:google下chromium项目的跨平台公共库: 2. vc_common_src:即HP_SOCKET项目中的 ...

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

    目录 . 引言 . 交叉编译 . Cygwin简介 . 静态库编译及使用 . 动态库编译及使用 . MinGW简介 . CodeBlocks简介 0. 引言 UNIX是一个注册商标,是要满足一大堆条件 ...

  4. linux下JUCE源码编译依赖库

    JUCE 源码https://github.com/julianstorer/JUCE 想在ubuntu下编译需要提前安装以下依赖库 sudo apt-get install mesa-common- ...

  5. Unity跨平台C/CPP动态库编译---可靠UDP网络库kcp基于CMake的各平台构建实践

    1.为什么需要动态库 a)提供原生代码(native code)的支持,也叫原生插件,但是我实践的是c/cpp跨平台动态库,这里不具体涉及安卓平台java库和ios平台的objectc库构建. b)某 ...

  6. 基于canvas实现的高性能、跨平台的股票图表库--clchart

    什么是 ClChart? ClChart是一个基于canvas创建的简单.高性能和跨平台的股票数据可视化开源项目.支持PC.webApp以及React Native和Weex等平台.在React Na ...

  7. 跨平台高效率Lua网络库 ( 同步形式的API ,底层是异步非阻塞)

    Joynet 项目地址:https://github.com/IronsDu/Joynet 介绍 high performance network library for lua, based on  ...

  8. 推荐一个c++小巧开源且跨平台的图像解码库

    该图像解码库仅仅三个文件. 图像处理封装: spot.cpp spot.h 解码库实现: spot.c 支持图片文件格式如下: File format Read Write BMP files yes ...

  9. 使用SWT技术的跨平台移动应用开发库Tabris

    1. http://developer.eclipsesource.com/tabris/ 2. 多平台.原生程序级别的性能 3. 开源/教育性的项目免费,意思就是商业项目收费 4. 目标,让懂jav ...

随机推荐

  1. 开源的Android开发框架-------PowerFramework使用心得(三)内置浏览器BrowserActivity

    使用内置浏览器必须是引用源码的方式(因为jar中不能打包布局文件等资源).内置浏览器是一个继承自BaseActivity的普通Activity,使用WebView实现. 1.简单的打开内置浏览器 In ...

  2. NSString截取字符串

     NSString 是经常会用到的,很多时候需要对字符串进行一些处理,本文简单介绍字符串截取操作: 比如: 1.定义一个字符串a, 截取a的某一个部分(子串) NSString *a = @" ...

  3. iOS中使用UIWebView与JS进行交互

    iOS中使用UIWebView与JS进行交互 前一段忙着面试和复习,这两天终于考完试了,下学期的实习也有了着落,把最近学的东西更新一下,首先是使用UIWebView与JS进行交互 在webView中我 ...

  4. Pythonchallenge一起来闯关

    http://www.pythonchallenge.com/是一个在线的python过关游戏,一共有33关.玩这个游戏对熟悉python用法及相关库的使用都很有好处. 目前做到了第九关.python ...

  5. 【USACO 3.1.3】丑数

    [描述] 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p1p2p3 (还有其它).这是 ...

  6. 《asp.net mvc3 高级编程》第二章 控制器

    一.控制器的角色 MVC模式中的控制器(Controller)主要负责响应用户的输入,并且在响应时通常会修改模型(Model).通过这种方式,MVC模式中的控制器主要关注的是应用程序流,输入数据的处理 ...

  7. Yii2的相关学习记录,初始化Yii2(二)

    前面已经将Yii2下载下来了,那我们就需要能实际的使用. 一.初始化,因为我都是在windows系统下,所以用cmd命令打开下载下来的Yii2的根目录.然后运行下面命令: init 会提示选择0为开发 ...

  8. jQuery之异步Ajax请求使用

    $.ajax({type:'',data:'',async:''...}) 参数: 1.cache: true缓存页面 false 不缓存页面 (默认: true,dataType为script和js ...

  9. 获取上海地区AQI质量数据Python脚本

    一个获取上海地区AQI质量的Python脚本 https://github.com/yanyueoo7/Raspberrypi/blob/master/GetPmData_Shanghai.py #! ...

  10. angular2 学习笔记 (Typescript)

    1.接口奇葩验证 interface Abc { name : string } function abc(obj : Abc) { } let ttc = { name: "adad&qu ...