VC++工程中加入 SplashScreen 原理释解
2006-07-23 11:25:17 来源:WEB开发网核心提示: BOOL CSplashWnd::Create(CWnd* pParentWnd){if (!m_bitmap.LoadBitmap(IDB_SPLASH))return FALSE;BITMAP bm;m_bitmap.GetBitmap(&bm);return CreateEx(0,A
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();
}
再看看CWinApp和CMainFrame类中发生了什么样的改变:
更多精彩
赞助商链接