每一个应用程序可能都需要一个“about box”和程序启动时一个“splash screen”(启动画面),大多数开发者都使用自带的““about dialog””。我创建了一个类CSplashScreen
,都可以处理这两者,使开发变的容易,有趣!从小的对话框组件程序到需要加在几分复杂程序,我都会使用这个类。
这个类有两个文件组成,SplashScreen.h 和 SplashScreen.cpp。这个类不需要MFC和.NET的支持!
这个类可以从资源编辑器中获取很多信息包括位图,版本字符串等等,显示在“splash screen”上。因此,在程序版本改变的时候,你不需要修改splash screen。
当程序启动时splash screen就会显示,有键盘按下,或者设定时间已过,splash screen就会消失。
Splash Screen Example
IDB_SPLASH
在连接库添加version.lib
ShowSplashScreen(HWND pParentWnd, LPCTSTR statusMessage, int millisecondsToDisplay)
函数有三个参数。
pParentWnd - splash screen的父窗口指针
statusMessage
- 显示在splash screen状态栏里的字符串
millisecondsToDisplay
- splash screen持续时间
为了显示splash screen,需要在程序初始化时,添加CSplashScreen::ShowSplashScreen();
#include "SplashScreen.h" int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; // display splash screen and have it turn off after 10 seconds CSplashScreen::ShowSplashScreen( hWnd, "http://applehome.com/", 10000); . . . while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; }
WndProc(…)
中添加
CSplashScreen::ShowSplashScreen()
#include "SplashScreen.h" LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: // Parse the menu selections: switch (LOWORD(wParam)) { case IDM_ABOUT: // display about box CSplashScreen::ShowSplashScreen( hWnd ); break; } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
IDB_SPLASH
位图上。能否创造一个专业的splash screen.取决于你们天才的设计师。版本字符串时写在位图之上的。
有三组字符串:Product Name,Body,和Status。Body是由company name, version, copyright, 和 comment strings一个或多个组成。
每一组 都有指定字符串在该组如何显示的静态变量:
m_xxxVerticalOffset
- empty space between the top of the bitmap and the first stringm_xxxVerticalHeight
- the maximum height of a group of stringsm_xxxLeftMargin
- the distance from the left side to the place stringsm_xxxRightMargin
- the distance from the right side to stringsm_xxxFontName
- the name of the font for strings m_xxxPointSize
- the point size used for strings, (-1,-1) ==> Calculate point sizem_xxxTextColor
- the color used for strings m_displayCompanyName
- true if displaying company name m_displayVersion
- true if displaying version m_displayCopyright
- true if displaying copyright m_displayComments
- true if displaying comments
CSplashScreen
类是在CSplashScreen::ShowSplashScreen()
被调用时实例化,键盘按下或者时间超过时,被删除。
最后,文章的例子代码,CSplashScreen
代码下载地址:http://download.csdn.net/detail/chenjintaoxp/7634865