VC++工程中加入SplashScreen原理释解
2010-05-12 20:35:28 来源:WEB开发网//是否使用SplashScreen
void CSplashWnd::EnableSplashScreen(BOOL bEnable)
{
c_bShowSplashWnd = bEnable;
}
//创建CsplashWnd对象,并调用Create()创建窗口
void CSplashWnd::ShowSplashScreen(CWnd* pParentWnd)
{
//如果不要显示SplashScreen或SplashWnd对象已经被创建则返回
if (!c_bShowSplashWnd || c_pSplashWnd != NULL)
return;
c_pSplashWnd = new CSplashWnd;
if (!c_pSplashWnd->Create(pParentWnd))
delete c_pSplashWnd;
else
c_pSplashWnd->UpdateWindow();
}
//装入SplashScreen欲显示位图,通过CreateEx()激发OnCreate()完成窗口创建与设置
BOOL CSplashWnd::Create(CWnd* pParentWnd)
{
if (!m_bitmap.LoadBitmap(IDB_SPLASH))
return FALSE;
BITMAP bm;
m_bitmap.GetBitmap(&bm);
return CreateEx(0,
AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
NULL,
WS_POPUP | WS_VISIBLE,
0,
0,
bm.bmWidth,
bm.bmHeight,
pParentWnd->GetSafeHwnd(),
NULL);
}
//销毁窗口,刷新框架
void CSplashWnd::HideSplashScreen()
{
DestroyWindow();
AfxGetMainWnd()->UpdateWindow();
}
//利用窗口创建结构创建窗口,并设置定时器在750ms后触发OnTimer()
int CSplashWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CenterWindow(); //窗口居中显示
SetTimer(1, 750, NULL); //设置定时器
return 0;
}
//将键盘和鼠标消息传递给CSplashWnd对象,以销毁窗口
BOOL CSplashWnd::PreTranslateAppMessage(MSG* pMsg)
{
if (c_pSplashWnd == NULL)
return FALSE;
if (pMsg->message == WM_KEYDOWN ||
pMsg->message == WM_SYSKEYDOWN ||
pMsg->message == WM_LBUTTONDOWN ||
pMsg->message == WM_RBUTTONDOWN ||
pMsg->message == WM_MBUTTONDOWN ||
pMsg->message == WM_NCLBUTTONDOWN ||
pMsg->message == WM_NCRBUTTONDOWN ||
pMsg->message == WM_NCMBUTTONDOWN)
{
c_pSplashWnd->HideSplashScreen();
return TRUE;
}
return FALSE;
}
void CSplashWnd::OnTimer(UINT nIDEvent)
{
HideSplashScreen();
}
更多精彩
赞助商链接