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