SplashScreen
开始学习wxWidgets。准备把学到的都记下来,算是自己的学习笔记。
今天写了一个SplashScreen的小例子。SplashScreen的意思通俗点来说就是在程序运行前先蹦出来的东东。举个例子,比如游侠网下载的游戏,每次运行前都会蹦出来一个小图片,停留几秒后,等它消失了才会进入游戏。
大致流程是:1. 加载需要的image handler,下表列出的是wx可用的image handler(可以看出目前只有PNG格式支持alpha通道)
wxBMPHandler | For loading and saving, always installed. |
wxPNGHandler | For loading (including alpha support) and saving. |
wxJPEGHandler | For loading and saving. |
wxGIFHandler | Only for loading, due to legal issues. |
wxPCXHandler | For loading and saving (see below). |
wxPNMHandler | For loading and saving (see below). |
wxTIFFHandler | For loading and saving. |
wxTGAHandler | For loading only. |
wxIFFHandler | For loading only. |
wxXPMHandler | For loading and saving. |
wxICOHandler | For loading and saving. |
wxCURHandler | For loading and saving. |
wxANIHandler | For loading only. |
2. Load图片。
通过wxBitmap::LoadFile( const wxString& name, wxBitmapType type )函数。
name是将要load进来得图片的名字,type是图片格式的类型,比如bmp格式的图片就是wxBITMAP_TYPE_BMP ,PNG格式的就是wxBITMAP_TYPE_PNG。。。
3. 可以创建SplashScreen了。
wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSIMPLE_BORDER|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP)
具体参数一看就明白意思了。bitmap就是上面第2步创建的,splashStyle是风格,例:wxSPLASH_CENTRE_ON_SCREEN。后面几个参数分别是 持续时间,父窗口指针, id号, 位置, 大小,样式。。
1wxImage::AddHandler(new wxPNGHandler);
2
3 wxBitmap bitmap;
4
5 bitmap.LoadFile(_T("splash.png"), wxBITMAP_TYPE_PNG);
6
7 wxSplashScreen* const splashScreen = new wxSplashScreen(bitmap,
8 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
9 -1, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize,
10 wxSIMPLE_BORDER|wxSTAY_ON_TOP);
11
12 Yield(); // 挂起消息
13
14 Sleep( 2000 );
15
16 delete splashScreen;
2
3 wxBitmap bitmap;
4
5 bitmap.LoadFile(_T("splash.png"), wxBITMAP_TYPE_PNG);
6
7 wxSplashScreen* const splashScreen = new wxSplashScreen(bitmap,
8 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
9 -1, NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize,
10 wxSIMPLE_BORDER|wxSTAY_ON_TOP);
11
12 Yield(); // 挂起消息
13
14 Sleep( 2000 );
15
16 delete splashScreen;
这样,程序在每次运行前,都会在先屏幕中央弹出splash.png这张图片,2秒终后,出现程序界面。。
版权声明:本篇为原创文章,允许转载,但转载时请务必以超链接形式标明文章的原始出处和作者信息。请尊重本人的劳动成果,谢谢!
小祥的BLOG http://xfxsworld.cnblogs.com