一日心血來潮,想給啓動畫面來個淡入淡出,於是去谷歌(google)查了半天,無果。但知道了AnimiateWindow 這個
#undef WINVER //取消原有版本定義,重新定義版本
#define WINVER 0x5000 //爲了使AnimateWindow函數可用
#include <afxwin.h>
然後在相關文件分別加入OnCreate,OnClose,OnEraseBkgnd和OnTimer消息函數。記得在相關構析函數內加入 :
SetTimer(1, 3000, NULL); //設定定時器1,定時3秒
BOOL CSplashWnd::OnCreate(LPCREATESTRUCT lpcs)
{
CenterWindow(); //窗口位於屏幕中心
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND); //淡入圖片0.5秒
return true;
}
OnClose消息函數是添加淡出窗口或背景位圖代碼:
void CSplashWnd::OnClose()
{
AnimateWindow(GetSafeHwnd(), 500, AW_BLEND | AW_HIDE); //淡出圖片0.5秒
CWnd::OnClose();
}
OnEraseBkgnd消息函數是添加背景 位圖 :
BOOL CSplashWnd::OnEraseBkgnd(CDC *pDC)
{
DDB mSplashBitmap;
mSplashBitmap.DisplayDDB(pDC, IDB_SPLASH); //顯示位圖資源IDB_SPLASH
return true;
}
OnTimer消息函數是添加定時關閉代碼:
void CSplashWnd::OnTimer(UINT nIDEvent)
{
KillTimer(1); //關閉定時器1
PostMessage(WM_CLOSE, 0, 0); //發送關閉窗口信息
}