`
zuroc
  • 浏览: 1290173 次
  • 性别: Icon_minigender_1
  • 来自: 江苏
社区版块
存档分类
最新评论

smartwin++之旅_1

    博客分类:
  • C++
阅读更多
= 概览 =

Smartwin++是一个体现了现代的C++设计思想的开源GUI库,授权方式是BSD.

它专注于Windows平台的GUI设计,并且可以支持WinCE平台。借助于WineLib,还可以在更多操作系统,比如Linux上运行.

官方网站:
http://smartwin.sourceforge.net

我用的编译环境是VS2005,Smartwin版本为2.0.下载安装包,一路next.然后到安装目录下运行相应项目进行编译从而得到smartwin的库,注意设置一下头文件目录.

然后自己新建一个空的Win32项目,注意设置一下头文件和库目录,另外注意

项目属性->C++->代码生成->运行时库

的设置要和编译smartwin时的设置相对应(默认为/MT和/MTD),否则会有一堆链接错误.

另外可以用/wd4819来禁用一些无用的警告.

OK,复制下面的Hello World代码编译一下看看.

#include "SmartWin.h"
using namespace SmartWin;


class HelloWinClass
    : public WidgetFactory< WidgetWindow, HelloWinClass >
{
private:
    WidgetMenuPtr    itsMainMenu;
    WidgetButtonPtr itsButton;
    WidgetCheckBoxPtr itsCheckBox;
  
public:
    void menuSayHello( WidgetMenuPtr menu, unsigned item )
    {
        createMessageBox().show( _T("Hello !" ), menu->getText( item ) );
    }

    void menuClose( WidgetMenuPtr menu, unsigned item )
    {
        close();
    }

    void buttonClicked( WidgetButtonPtr button )
    {
        if ( itsCheckBox->getChecked() ) {
            createMessageBox().show( _T("Hello World!" ), button->getText() );
        } else {
            createMessageBox().show( _T("Hello !" ), button->getText() );
        }
    }

    void initAndCreate()
    {
        createWindow();
        setText( _T("Hello SmartWin") );    // Title

        SmartWin::Rectangle desktop( getDesktopSize() );
        setBounds( desktop.top(0.2).left(0.3) , true );

        itsButton = createButton();
        itsButton->setText( _T("Hello from a button") );
        itsButton->onClicked( &HelloWinClass::buttonClicked );
        itsButton->setBounds( itsButton->getPosition(), Point( 200, 30 ), true );

        itsCheckBox = createCheckBox();
        itsCheckBox->setText( _T("&Global") );
        itsCheckBox->setBounds( itsButton->getPosition(), Point( 200, 30 ), true );

        // Creating main menu
        itsMainMenu = createMenu();
        WidgetMenuPtr file = itsMainMenu->appendPopup( _T("&MenuCommands") );
        int m = 1;
        file->appendItem( m++, _T("Hello from the menu"), &HelloWinClass::menuSayHello );
        file->appendItem( m++, _T("Close"), &HelloWinClass::menuClose );

#ifndef WINCE
        itsMainMenu->attach( this );
#endif
        layout();
        onSized( &HelloWinClass::isResized );  
    }

    void isResized( const WidgetSizedEventResult & sz )
    {
        layout();
    }

    void layout()
    {
        SmartWin::Place p;
        SmartWin::Rectangle r( getClientAreaSize() );
        p.setBoundsBorders( r, 4, 4 );
           
        itsCheckBox->setPositionPerPlace( p );
        itsButton->setPositionPerPlace( p );
    }
};

int SmartWinMain( Application & app )
{
    HelloWinClass * testHello = new HelloWinClass;
    testHello->initAndCreate();
    return app.run();
}

//END


= 一个窗口 =

Smartwin库中的形式main如下

int SmartWinMain( Application & app )
{
    //你的代码
    return app.run();
}

为了生成一个可见的窗体,你首先需要从WidgetFactory集成一个类.

OK,我们新建一个头文件,代码如下

#include "SmartWin.h"
using namespace SmartWin;

class MyWidget
    : public WidgetFactory

 

分享到:
评论

相关推荐

    SmartWin++-开源

    SmartWin ++是一个C ++模板GUI库,旨在提供Windows API的灵活性,而又避免了MFC / WTL提供的麻烦和类型安全性。 Windows API(以前称为Win32 API)的灵活,可扩展的抽象。

    SmartWin基于WinAPI的GUI框架

    smartwin 基于WinAPI的GUI框架,而不是基于MFC/WTL

    Code Blocks 8.02 带mingw

    Code::Blocks提供了许多工程模板,这包括:控制台应用、DirectX应用、动态连接库、FLTK应用、GLFW应用、Irrlicht工程、OGRE应用、OpenGL应用、QT应用、SDCC应用、SDL应用、SmartWin应用、静态库、Win32 GUI应用、...

    Code Blocks

     Code::Blocks提供了许多工程模板,这包括:控制台应用、DirectX应用、动态连接库、FLTK应用、GLFW应用、Irrlicht工程、OGRE应用、OpenGL应用、QT应用、SDCC应用、SDL应用、SmartWin应用、静态库、Win32 GUI应用、...

    Code::Blocks 8.02 GCC 4.40 汉化包

     Code::Blocks提供了许多工程模板,这包括:控制台应用、DirectX应用、动态连接库、FLTK应用、GLFW应用、Irrlicht工程、OGRE应用、OpenGL应用、QT应用、SDCC应用、SDL应用、SmartWin应用、静态库、Win32 GUI应用、...

Global site tag (gtag.js) - Google Analytics